This is an automated email from the ASF dual-hosted git repository.
fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new c2461f995f Core: Don't remove trailing slash from absolute paths
(#12389)
c2461f995f is described below
commit c2461f995f0e1fec889d09e56924a9c5afaa80c9
Author: Alexandre Dutra <[email protected]>
AuthorDate: Mon Feb 24 09:03:59 2025 +0100
Core: Don't remove trailing slash from absolute paths (#12389)
Fixes #12373
---
.../java/org/apache/iceberg/rest/HTTPRequest.java | 16 ++++++++++------
.../org/apache/iceberg/rest/TestHTTPRequest.java | 21 ++++++++++++++++++++-
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/core/src/main/java/org/apache/iceberg/rest/HTTPRequest.java
b/core/src/main/java/org/apache/iceberg/rest/HTTPRequest.java
index 41921d946c..ce4b65b23e 100644
--- a/core/src/main/java/org/apache/iceberg/rest/HTTPRequest.java
+++ b/core/src/main/java/org/apache/iceberg/rest/HTTPRequest.java
@@ -53,13 +53,17 @@ public interface HTTPRequest {
*/
@Value.Lazy
default URI requestUri() {
- // if full path is provided, use the input path as path
- String fullPath =
- (path().startsWith("https://") || path().startsWith("http://"))
- ? path()
- : String.format("%s/%s", baseUri(), path());
+ String fullPath;
+ if (path().startsWith("https://") || path().startsWith("http://")) {
+ // if path is an absolute URI, use it as is
+ fullPath = path();
+ } else {
+ String baseUri = RESTUtil.stripTrailingSlash(baseUri().toString());
+ fullPath = RESTUtil.stripTrailingSlash(String.format("%s/%s", baseUri,
path()));
+ }
+
try {
- URIBuilder builder = new
URIBuilder(RESTUtil.stripTrailingSlash(fullPath));
+ URIBuilder builder = new URIBuilder(fullPath);
queryParameters().forEach(builder::addParameter);
return builder.build();
} catch (URISyntaxException e) {
diff --git a/core/src/test/java/org/apache/iceberg/rest/TestHTTPRequest.java
b/core/src/test/java/org/apache/iceberg/rest/TestHTTPRequest.java
index 84e1b0830c..87bc250663 100644
--- a/core/src/test/java/org/apache/iceberg/rest/TestHTTPRequest.java
+++ b/core/src/test/java/org/apache/iceberg/rest/TestHTTPRequest.java
@@ -58,6 +58,17 @@ class TestHTTPRequest {
.build(),
URI.create(
"http://localhost:8080/foo/v1/namespaces/ns/tables?pageToken=1234&pageSize=10")),
+ Arguments.of(
+ ImmutableHTTPRequest.builder()
+ .baseUri(
+ URI.create("http://localhost:8080/foo/")) // trailing
slash should be removed
+ .method(HTTPRequest.HTTPMethod.GET)
+ .path("v1/namespaces/ns/tables/") // trailing slash should be
removed
+ .putQueryParameter("pageToken", "1234")
+ .putQueryParameter("pageSize", "10")
+ .build(),
+ URI.create(
+
"http://localhost:8080/foo/v1/namespaces/ns/tables?pageToken=1234&pageSize=10")),
Arguments.of(
ImmutableHTTPRequest.builder()
.baseUri(URI.create("http://localhost:8080/foo"))
@@ -71,7 +82,15 @@ class TestHTTPRequest {
.method(HTTPRequest.HTTPMethod.GET)
.path("http://authserver.com/token") // absolute path HTTP
.build(),
- URI.create("http://authserver.com/token")));
+ URI.create("http://authserver.com/token")),
+ Arguments.of(
+ ImmutableHTTPRequest.builder()
+ .baseUri(URI.create("http://localhost:8080/foo"))
+ .method(HTTPRequest.HTTPMethod.GET)
+ // absolute path with trailing slash: should be preserved
+ .path("http://authserver.com/token/")
+ .build(),
+ URI.create("http://authserver.com/token/")));
}
@Test