Repository navigation
fix(s3): do not persist aws-chunked as an object's Content-Encoding (#428) - #437
Merged
Merged
Conversation
…428) A SigV4 streaming upload — what every AWS SDK sends for a body it does not buffer — arrives with `Content-Encoding: aws-chunked`. putObject stored that value verbatim, so GetObject/HeadObject reported the object as aws-chunked-encoded for bytes substrate had already dechunked. aws-chunked is a transfer encoding. It describes the chunk-signature framing the body arrived in, not how the stored object is encoded. AWS defines Content-Encoding as "what content encodings have been applied to the object and thus what decoding mechanisms must be applied"; PutObject's reference never lists aws-chunked as persisted metadata, and CreateMultipartUpload scopes that value to directory buckets. So a consumer dispatching decompression on the header was handed a name that is not a content codec, for content needing no decoding — and real AWS omits the header entirely, so nothing revealed the difference until a round-trip failed. Both write paths now resolve the header through one s3PersistedContentEncoding helper. That shape is the point: putObject and createMultipartUpload having drifted apart on this exact header is what #406 was, and filtering in only one of them would set up the same bug again. A genuine codec sent alongside (`aws-chunked, gzip`) is kept in order — dropping the header wholesale would lose the codec that *is* applied, which is #406's failure from the other side. CopyObject is deliberately not a caller: its COPY branch inherits the source object's already-filtered value, and a copy request carries no body, so no SDK sends a transfer encoding on it. Tests: TestS3_PutObject_AWSChunked now asserts the persisted value on both HEAD and GET, closing the gap that let this survive — it sent the header but checked only Content-Length. New table tests cover both write paths over aws-chunked alone, before and after a codec, unspaced, and mixed-case. Header-name casing is asserted through an export_test wrapper rather than an HTTP request, because net/http canonicalizes on the way in and an HTTP-level casing test would assert nothing about the plugin. Verified by reverting the filter: every aws-chunked row fails, and the plain-codec and absent rows still pass. Closes #428
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
A SigV4 streaming upload — what every AWS SDK sends for a body it does not buffer — arrives with
Content-Encoding: aws-chunked.putObjectstored that value verbatim, soGetObject/HeadObjectreported the object asaws-chunked-encoded for bytes substrate had already dechunked.aws-chunkedis a transfer encoding — it describes the chunk-signature framing the body arrived in, not how the stored object is encoded. AWS definesContent-Encodingas "what content encodings have been applied to the object and thus what decoding mechanisms must be applied"; PutObject's reference never listsaws-chunkedas persisted metadata, and CreateMultipartUpload scopes that value to directory buckets. So a consumer dispatching decompression on the header was handed a name that is not a content codec, for content needing no decoding — and real AWS omits the header entirely, so nothing revealed the difference until a round-trip failed.The fix
Both write paths now resolve the header through one
s3PersistedContentEncodinghelper:Content-Encodinggzipgzipaws-chunkedaws-chunked, gzipgzipgzip, aws-chunkedgzipAWS-Chunked, brbrThe shared-helper shape is the point, not incidental.
putObjectandcreateMultipartUploadhaving drifted apart on this exact header is what #406 was; filtering in only one of them would set up the same bug again. A genuine codec sent alongside (aws-chunked, gzip, as an SDK streaming a compressed body sends) is kept in order — dropping the header wholesale would lose the codec that is applied, which is #406's failure from the other side.CopyObjectis deliberately not a caller: itsCOPYbranch inherits the source object's already-filtered value, and a copy request carries no body, so no SDK sends a transfer encoding on it. Recorded in the helper's doc comment and indocs/services.mdso it does not read as an oversight.Tests
TestS3_PutObject_AWSChunkednow asserts the persisted value on both HEAD and GET — closing the gap that let this survive, since it sent the header but checked onlyContent-Length. New table tests cover both write paths across all the rows above.Header-name casing is asserted through an
export_test.gowrapper rather than an HTTP request:net/httpcanonicalizes header names on the way in, so a lowercase key never reaches the plugin from an HTTP test and an apparent test of it would assert nothing. It matters because substrate buildsAWSRequestvalues in-process too (betty_cfn.go).Verified by reverting the filter: every
aws-chunkedrow fails, and the plain-codec and absent rows still pass.Verification
gofmt·go build ./...·go vet ./...·golangci-lint run ./...(0 issues) ·make test(race) ·test/e2e·make docs-reference-check docs-versions— all clean.AWS references consulted
aws-chunkedappears nowhere in the request-header documentation.aws-chunkedvalue is supported in this header field", i.e. scoped to directory buckets, which substrate does not model.Closes #428