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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-4270-c125c0bf0cfa94a096065c2b7f9864cfcf7b7c78
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit ce5a1953b228dafc8a31b13751485099eab1f6c6
Author: Ankit Raj <[email protected]>
AuthorDate: Wed Nov 18 04:52:42 2026 +0000

    Replace S3 remote signer headers instead of appending them (#4270)
---
 pyiceberg/io/fsspec.py  |  2 ++
 tests/io/test_fsspec.py | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py
index 25843152a..e9d17631f 100644
--- a/pyiceberg/io/fsspec.py
+++ b/pyiceberg/io/fsspec.py
@@ -162,6 +162,8 @@ class S3V4RestSigner(S3RequestSigner):
             raise SignError(f"Failed to sign request {response.status_code}: 
{signer_body}") from e
 
         for key, value in response_json["headers"].items():
+            # Replace instead of append, so a header the request already has 
is not sent twice
+            del request.headers[key]
             request.headers.add_header(key, ", ".join(value))
 
         request.url = response_json["uri"]
diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py
index e7b2c8268..b539edd84 100644
--- a/tests/io/test_fsspec.py
+++ b/tests/io/test_fsspec.py
@@ -1032,6 +1032,42 @@ def test_s3v4_rest_signer(requests_mock: Mocker) -> None:
     assert requests_mock.last_request.headers["User-Agent"] == _user_agent()
 
 
+def test_s3v4_rest_signer_replaces_existing_headers(requests_mock: Mocker) -> 
None:
+    requests_mock.post(
+        f"{TEST_URI}/v1/aws/s3/sign",
+        json={
+            "uri": "https://bucket/metadata/file.avro";,
+            "headers": {
+                "Authorization": ["AWS4-HMAC-SHA256 Credential=..., 
SignedHeaders=..., Signature=..."],
+                "x-amz-content-sha256": ["UNSIGNED-PAYLOAD"],
+                "User-Agent": ["Botocore/1.27.59"],
+            },
+            "extensions": {},
+        },
+        status_code=200,
+    )
+
+    request = AWSRequest(
+        method="PUT",
+        url="https://bucket/metadata/file.avro";,
+        headers={
+            "User-Agent": "Botocore/1.27.59",
+            "X-Amz-Content-SHA256": "STREAMING-UNSIGNED-PAYLOAD-TRAILER",
+        },
+        data=b"",
+        params={},
+        auth_path="/metadata/file.avro",
+    )
+    request.context = {"client_region": "us-west-2"}
+
+    signer = S3V4RestSigner(properties={"token": "abc", "uri": TEST_URI})
+    signer(request)
+
+    assert request.headers.get_all("x-amz-content-sha256") == 
["UNSIGNED-PAYLOAD"]
+    assert request.headers.get_all("User-Agent") == ["Botocore/1.27.59"]
+    assert len(request.headers.get_all("Authorization")) == 1
+
+
 @pytest.mark.s3
 def test_s3v4_rest_signer_write_read_delete(request: pytest.FixtureRequest, 
requests_mock: Mocker) -> None:
     """Test writing, reading, and deleting an S3 file through a REST signing 
service"""

Reply via email to