8000 fix detection of aws-chunked encoding (#8712) · codeperl/localstack@b0623d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0623d2

Browse files
authored
fix detection of aws-chunked encoding (localstack#8712)
1 parent 602a4ad commit b0623d2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

localstack/services/s3/provider.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,10 @@ def upload_part(self, context: RequestContext, request: UploadPartRequest) -> Up
813813

814814
body = request.get("Body")
815815
headers = context.request.headers
816-
if body and "aws-chunked" in (headers.get("Content-Encoding") or "").lower():
816+
# AWS specifies that the `Content-Encoding` should be `aws-chunked`, but some SDK don't set it.
817+
# Rely on the `x-amz-content-sha256` which is a more reliable indicator that the request is streamed
818+
content_sha_256 = (headers.get("x-amz-content-sha256") or "").upper()
819+
if body and content_sha_256 and content_sha_256.startswith("STREAMING-"):
817820
# this is a chunked request, we need to properly decode it while setting the key value
818821
decoded_content_length = int(headers.get("x-amz-decoded-content-length", 0))
819822
buffer = io.BytesIO()

localstack/services/s3/provider_stream.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ def put_object(
125125
key_object.checksum_algorithm = checksum_algorithm
126126

127127
headers = context.request.headers
128-
if "aws-chunked" in (headers.get("Content-Encoding") or "").lower():
128+
# AWS specifies that the `Content-Encoding` should be `aws-chunked`, but some SDK don't set it.
129+
# Rely on the `x-amz-content-sha256` which is a more reliable indicator that the request is streamed
130+
content_sha_256 = (headers.get("x-amz-content-sha256") or "").upper()
131+
if content_sha_256 and content_sha_256.startswith("STREAMING-"):
129132
# this is a chunked request, we need to properly decode it while setting the key value
130133
decoded_content_length = int(headers.get("x-amz-decoded-content-length", 0))
131134
key_object.set_value_from_chunked_payload(body, decoded_content_length)
@@ -278,7 +281,10 @@ def upload_part(self, context: RequestContext, request: UploadPartRequest) -> Up
278281
body = request.get("Body") or BytesIO()
279282
decoded_content_length = None
280283
headers = context.request.headers
281-
if "aws-chunked" in (headers.get("Content-Encoding") or "").lower():
284+
# AWS specifies that the `Content-Encoding` should be `aws-chunked`, but some SDK don't set it.
285+
# Rely on the `x-amz-content-sha256` which is a more reliable indicator that the request is streamed
286+
content_sha_256 = (headers.get("x-amz-content-sha256") or "").upper()
287+
if content_sha_256 and content_sha_256.startswith("STREAMING-"):
282288
# this is a chunked request, we need to properly decode it while setting the key value
283289
decoded_content_length = int(headers.get("x-amz-decoded-content-length", 0))
284290

0 commit comments

Comments
 (0)
0