Skip to content

fix(s3): carry Content-Encoding through multipart upload (#406) - #424

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/406-multipart-content-encoding
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/406-multipart-content-encoding

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

CreateMultipartUpload accepted Content-Encoding and discarded it, so an object
assembled from parts came back with no encoding header while the identical body
written through PutObject came back correctly. Two upload paths disagreed about
one object property.

S3MultipartUpload now records ContentEncoding at create time and
CompleteMultipartUpload applies 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 the
sole place the codec can be supplied, so an encoding not carried on the upload
record is lost for good.

Why it mattered

objectfs compresses above its multipart threshold and read the object back as
uncompressed, surfacing as a false DATA_CORRUPTION against application code that
was behaving correctly. The symmetric risk is worse: a test asserting the header is
absent passed vacuously.

Header casing

Both header reads in createMultipartUpload now use headerValueFold, matching
resolveStorageClass and resolveUploadChecksum in the same function.

To be explicit 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 constructs
AWSRequest values in-process (betty_cfn.go) where net/http canonicalization
never runs. The adjacent Content-Type switch is a consistency change, not a bug
fix.

Scope

  • The value is stored verbatim. putObject persisting aws-chunked as a
    Content-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 "worth
    checking" on the issue) have no S3Object fields at all, so they are a feature
    across 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 over gzip, zstd, br and ""
(absent ⇒ header not emitted), asserting on both HEAD and GET, and that
x-amz-meta-* survives alongside the encoding (metadata working while encoding
vanished is exactly what the reporter saw).

No lowercase-header case: s3Request goes through ServeHTTP, which canonicalizes,
so such a test would assert nothing. Rationale is in a code comment.

Verified the test can fail: removing ContentEncoding: upload.ContentEncoding
produces -br / + on the brotli row.

Verification

gofmt clean · go build ./... · go vet ./... · golangci-lint run ./... (0
issues) · make test (race) · make docs-reference-check · test/e2e — all green.

Closes #406

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

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 7e2bf74 into main Aug 1, 2026
15 checks passed
@scttfrdmn
scttfrdmn deleted the fix/406-multipart-content-encoding branch August 1, 2026 05:28
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: CreateMultipartUpload drops Content-Encoding, so multipart objects lose it

1 participant