Repository navigation
fix(s3): carry Content-Encoding through multipart upload (#406) - #424
Merged
Merged
Conversation
CreateMultipartUpload accepted Content-Encoding and threw it away, so an object uploaded in parts round-tripped with no encoding header while the identical body through PutObject round-tripped correctly. A consumer that gzips above its multipart threshold therefore reads back a body it must treat as uncompressed — objectfs saw this as a false DATA_CORRUPTION against application code that was doing the right thing. The symmetric risk is worse: a test asserting the header is absent passes vacuously. The upload record is the only correct home for the value. Per the CompleteMultipartUpload reference, Complete accepts no object-metadata headers at all (only checksums, x-amz-mp-object-size, request-payer, SSE-C and conditional headers), so Create is the sole place the codec can be supplied and it must be carried forward on S3MultipartUpload. Read the header with headerValueFold, as resolveStorageClass and resolveUploadChecksum in the same function already do. Be honest about the evidence: no S3 test builds an AWSRequest literal, so headerValueFold is not needed to make any test pass. It rests on protocol correctness — RFC 9110 header names are case-insensitive and substrate builds requests in-process too (betty_cfn.go), where net/http canonicalization does not apply. The adjacent Content-Type switch to headerValueFold is a consistency change, not a bug fix. Store the value verbatim; aws-chunked filtering on the PutObject path is a real but separate defect, tracked on its own. Closes #406
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Aug 1, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
CreateMultipartUploadacceptedContent-Encodingand discarded it, so an objectassembled from parts came back with no encoding header while the identical body
written through
PutObjectcame back correctly. Two upload paths disagreed aboutone object property.
S3MultipartUploadnow recordsContentEncodingat create time andCompleteMultipartUploadapplies it to the assembled object.Why the upload record is the only correct home
Per the CompleteMultipartUpload reference,
Complete accepts no object-metadata headers at all — only checksums,
x-amz-mp-object-size, request-payer, SSE-C and conditional headers. Create is thesole place the codec can be supplied, so an encoding not carried on the upload
record is lost for good.
Why it mattered
objectfscompresses above its multipart threshold and read the object back asuncompressed, surfacing as a false
DATA_CORRUPTIONagainst application code thatwas behaving correctly. The symmetric risk is worse: a test asserting the header is
absent passed vacuously.
Header casing
Both header reads in
createMultipartUploadnow useheaderValueFold, matchingresolveStorageClassandresolveUploadChecksumin the same function.To be explicit about the evidence: no S3 test builds an
AWSRequestliteral, soheaderValueFoldis not needed to make any test pass. It rests on protocolcorrectness — RFC 9110 header names are case-insensitive, and substrate constructs
AWSRequestvalues in-process (betty_cfn.go) wherenet/httpcanonicalizationnever runs. The adjacent
Content-Typeswitch is a consistency change, not a bugfix.
Scope
putObjectpersistingaws-chunkedas aContent-Encoding is a real but separate defect, filed on its own so a shared
helper can fix both write paths at once rather than conflating it with this
parity fix.
Cache-Control/Content-Disposition/Content-Language(raised as "worthchecking" on the issue) have no
S3Objectfields at all, so they are a featureacross 4 headers × 5 sites, not this three-line change. Documented as unmodeled;
filed separately. The storage-class half of that same suggestion already works
(S3: no storage class on objects; InvalidObjectState unreachable; CopyObject metadata semantics #398).
Tests
TestS3_Multipart_ContentEncoding— table overgzip,zstd,brand""(absent ⇒ header not emitted), asserting on both HEAD and GET, and that
x-amz-meta-*survives alongside the encoding (metadata working while encodingvanished is exactly what the reporter saw).
No lowercase-header case:
s3Requestgoes throughServeHTTP, which canonicalizes,so such a test would assert nothing. Rationale is in a code comment.
Verified the test can fail: removing
ContentEncoding: upload.ContentEncodingproduces
-br / +on the brotli row.Verification
gofmtclean ·go build ./...·go vet ./...·golangci-lint run ./...(0issues) ·
make test(race) ·make docs-reference-check·test/e2e— all green.Closes #406