Skip to content

Commit 619c6d6

Browse files
authored
Preserve custom content-encoding value when setting aws-chunked (#4099)
## Motivation and Context aws-sdk-rust#1281 ## Description When setting `aws-chunked` to the `Content-Encoding` header for streaming APIs, we overwrite an existing custom value, if any provided by the customer. The expected behavior is to support multiple values as described in [the documentation](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html). ## Testing Updated existing unit test to account for a custom `Content-Encoding` header value. ## Checklist - [x] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent e4f4e92 commit 619c6d6

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

.changelog/1745291346.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
applies_to:
3+
- aws-sdk-rust
4+
authors:
5+
- ysaito1001
6+
references:
7+
- aws-sdk-rust#1281
8+
breaking: false
9+
new_feature: false
10+
bug_fix: true
11+
---
12+
Fix an issue where a custom `Content-Encoding` header was incorrectly overwritten by the `aws-chunked` header value.

aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ fn wrap_streaming_request_body_in_checksum_calculating_body(
377377
http::header::HeaderName::from_static("x-amz-decoded-content-length"),
378378
HeaderValue::from(original_body_size),
379379
);
380-
headers.insert(
380+
// The target service does not depend on where `aws-chunked` appears in the `Content-Encoding` header,
381+
// as it will ultimately be stripped.
382+
headers.append(
381383
http::header::CONTENT_ENCODING,
382384
HeaderValue::from_str(AWS_CHUNKED)
383385
.map_err(BuildError::other)

aws/sdk/integration-tests/s3/tests/checksums.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ async fn test_checksum_on_streaming_request<'a>(
193193
.put_object()
194194
.bucket("test-bucket")
195195
.key("test.txt")
196+
.content_encoding("custom")
196197
.body(body)
197198
.checksum_algorithm(checksum_algorithm)
198199
.send()
@@ -214,9 +215,7 @@ async fn test_checksum_on_streaming_request<'a>(
214215
let content_length = headers
215216
.get("Content-Length")
216217
.expect("Content-Length header exists");
217-
let content_encoding = headers
218-
.get("Content-Encoding")
219-
.expect("Content-Encoding header exists");
218+
let content_encoding = headers.get_all("Content-Encoding").collect::<Vec<_>>();
220219

221220
assert_eq!(
222221
HeaderValue::from_static("STREAMING-UNSIGNED-PAYLOAD-TRAILER"),
@@ -228,11 +227,9 @@ async fn test_checksum_on_streaming_request<'a>(
228227
x_amz_trailer,
229228
"x-amz-trailer is incorrect"
230229
);
231-
assert_eq!(
232-
HeaderValue::from_static(aws_runtime::content_encoding::header_value::AWS_CHUNKED),
233-
content_encoding,
234-
"content-encoding wasn't set to aws-chunked"
235-
);
230+
// The position for `aws-chunked` in `content_encoding` doesn't matter for the target service.
231+
// The expected here just reflects the current behavior of appending `aws-chunked` to the header.
232+
assert_eq!(vec!["custom", "aws-chunked"], content_encoding);
236233

237234
// The length of the string "Hello world"
238235
assert_eq!(

0 commit comments

Comments
 (0)