You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by et...@apache.org on 2025/02/24 08:14:11 UTC

(iceberg) branch 1.8.x updated: Core: Don't remove trailing slash from absolute paths (#12390)

This is an automated email from the ASF dual-hosted git repository.

etudenhoefner pushed a commit to branch 1.8.x
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/1.8.x by this push:
     new 6c65b8a223 Core: Don't remove trailing slash from absolute paths (#12390)
6c65b8a223 is described below

commit 6c65b8a2236ee6de62b61b142325b3373bced943
Author: Alexandre Dutra <ad...@users.noreply.github.com>
AuthorDate: Mon Feb 24 09:14:06 2025 +0100

    Core: Don't remove trailing slash from absolute paths (#12390)
    
    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