Skip to content

Commit a8deac9

Browse files
fix(rest): handle empty body in AWS SigV4 signing
1 parent b0a7878 commit a8deac9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pyiceberg/catalog/rest/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,14 @@ def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None: # pylin
434434
params = dict(parse.parse_qsl(query))
435435

436436
# remove the connection header as it will be updated after signing
437-
del request.headers["connection"]
437+
if "connection" in request.headers:
438+
del request.headers["connection"]
439+
# For empty bodies, explicitly set the content hash header to the SHA256 of an empty string
440+
body = request.body
441+
if body in (None, b"", ""):
442+
request.headers["x-amz-content-sha256"] = (
443+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
444+
)
438445

439446
aws_request = AWSRequest(
440447
method=request.method, url=url, params=params, data=request.body, headers=dict(request.headers)

0 commit comments

Comments
 (0)