Skip to content

fix(s3): do not persist aws-chunked as an object's Content-Encoding (#428) - #437

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/428-aws-chunked
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/428-aws-chunked

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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.

The fix

Both write paths now resolve the header through one s3PersistedContentEncoding helper:

Request Content-Encoding Recorded
gzip gzip
absent absent
aws-chunked absent
aws-chunked, gzip gzip
gzip, aws-chunked gzip
AWS-Chunked, br br

The shared-helper shape is the point, not incidental. putObject and createMultipartUpload having 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.

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. Recorded in the helper's doc comment and in docs/services.md so it does not read as an oversight.

Tests

TestS3_PutObject_AWSChunked now asserts the persisted value on both HEAD and GET — closing the gap that let this survive, since it sent the header but checked only Content-Length. New table tests cover both write paths across all the rows above.

Header-name casing is asserted through an export_test.go wrapper rather than an HTTP request: net/http canonicalizes 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 builds AWSRequest values in-process too (betty_cfn.go).

Verified by reverting the filter: every aws-chunked row 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

  • PutObject — aws-chunked appears nowhere in the request-header documentation.
  • CreateMultipartUpload — "For directory buckets, only the aws-chunked value is supported in this header field", i.e. scoped to directory buckets, which substrate does not model.

Closes #428

…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

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 167a26f into main Aug 1, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/428-aws-chunked branch August 1, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3: putObject persists aws-chunked as Content-Encoding

1 participant