Skip to content

Commit 6c65b8a

Browse files
authored
Core: Don't remove trailing slash from absolute paths (#12390)
Fixes #12373
1 parent 3c6bf24 commit 6c65b8a

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

core/src/main/java/org/apache/iceberg/rest/HTTPRequest.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ enum HTTPMethod {
5353
*/
5454
@Value.Lazy
5555
default URI requestUri() {
56-
// if full path is provided, use the input path as path
57-
String fullPath =
58-
(path().startsWith("https://") || path().startsWith("http://"))
59-
? path()
60-
: String.format("%s/%s", baseUri(), path());
56+
String fullPath;
57+
if (path().startsWith("https://") || path().startsWith("http://")) {
58+
// if path is an absolute URI, use it as is
59+
fullPath = path();
60+
} else {
61+
String baseUri = RESTUtil.stripTrailingSlash(baseUri().toString());
62+
fullPath = RESTUtil.stripTrailingSlash(String.format("%s/%s", baseUri, path()));
63+
}
64+
6165
try {
62-
URIBuilder builder = new URIBuilder(RESTUtil.stripTrailingSlash(fullPath));
66+
URIBuilder builder = new URIBuilder(fullPath);
6367
queryParameters().forEach(builder::addParameter);
6468
return builder.build();
6569
} catch (URISyntaxException e) {

core/src/test/java/org/apache/iceberg/rest/TestHTTPRequest.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ public static Stream<Arguments> validRequestUris() {
5858
.build(),
5959
URI.create(
6060
"http://localhost:8080/foo/v1/namespaces/ns/tables?pageToken=1234&pageSize=10")),
61+
Arguments.of(
62+
ImmutableHTTPRequest.builder()
63+
.baseUri(
64+
URI.create("http://localhost:8080/foo/")) // trailing slash should be removed
65+
.method(HTTPRequest.HTTPMethod.GET)
66+
.path("v1/namespaces/ns/tables/") // trailing slash should be removed
67+
.putQueryParameter("pageToken", "1234")
68+
.putQueryParameter("pageSize", "10")
69+
.build(),
70+
URI.create(
71+
"http://localhost:8080/foo/v1/namespaces/ns/tables?pageToken=1234&pageSize=10")),
6172
Arguments.of(
6273
ImmutableHTTPRequest.builder()
6374
.baseUri(URI.create("http://localhost:8080/foo"))
@@ -71,7 +82,15 @@ public static Stream<Arguments> validRequestUris() {
7182
.method(HTTPRequest.HTTPMethod.GET)
7283
.path("http://authserver.com/token") // absolute path HTTP
7384
.build(),
74-
URI.create("http://authserver.com/token")));
85+
URI.create("http://authserver.com/token")),
86+
Arguments.of(
87+
ImmutableHTTPRequest.builder()
88+
.baseUri(URI.create("http://localhost:8080/foo"))
89+
.method(HTTPRequest.HTTPMethod.GET)
90+
// absolute path with trailing slash: should be preserved
91+
.path("http://authserver.com/token/")
92+
.build(),
93+
URI.create("http://authserver.com/token/")));
7594
}
7695

7796
@Test

0 commit comments

Comments
 (0)