fix(s3): trim whitespace and match aws-chunked case-insensitively in Content-Encoding

Content-Encoding is a comma-separated list of content-coding tokens with
optional surrounding whitespace, and token names are case-insensitive
per RFC 9110 Section 8.4.

Previously, trimAwsChunkedContentEncoding split on commas and compared
each raw segment against "aws-chunked" with exact string equality. Inputs
such as "gzip, aws-chunked" or "AWS-Chunked" retained the transport
coding in stored object metadata, and "aws-chunked, gzip" left a leading
space in the persisted encoding.

Trim surrounding whitespace on each comma-separated coding token and
match "aws-chunked" with strings.EqualFold. Update the corresponding
whitespace cases in TestExtractReplicationMetadataPreservesNormalizedMetadata
and add unit tests in TestTrimAwsChunkedContentEncoding.

Signed-off-by: lingyicute <xlyxinglinyi@gmail.com>
This commit is contained in:
lingyicute
2026-11-28 09:52:43 +00:00
parent 11682b125d
commit 840615c357
3 changed files with 34 additions and 4 deletions
+5 -1
View File
@@ -370,7 +370,11 @@ func trimAwsChunkedContentEncoding(contentEnc string) (trimmedContentEnc string)
}
var newEncs []string
for enc := range strings.SplitSeq(contentEnc, ",") {
if enc != streamingContentEncoding {
// Content-Encoding is a comma separated list with optional
// whitespace around each coding, and coding names are
// case-insensitive, e.g. "gzip, aws-chunked".
enc = strings.TrimSpace(enc)
if !strings.EqualFold(enc, streamingContentEncoding) {
newEncs = append(newEncs, enc)
}
}