Skip to content

feat(s3): persist Cache-Control, Content-Disposition, Content-Language, Expires (#430) - #441

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/430-s3-system-metadata
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/430-s3-system-metadata

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #430

Stacked on #440 (fix/429-sqs-createqueue-errors), which is itself stacked on #438 — all three touch CHANGELOG.md. Bases retarget automatically as each merges.

The gap

S3Object had no fields for these at all. Substrate accepted the headers on write and silently discarded them, so GetObject/HeadObject never reported them. A consumer asserting that an attachment; filename= download name or a cache lifetime survives an upload got a green test verifying nothing — the write appeared to succeed. Real S3 persists all of them as object metadata and returns them on every read.

One declaration, not four fields × five sites

The four live in one embedded struct, S3SystemMetadata, shared by S3Object and S3MultipartUpload. That is the structural point of the change rather than a style preference: the two write paths drifting apart on a single header is exactly what #406 was. With one declaration, CompleteMultipartUpload carries the family across in a single assignment, so a header added to the family is carried by both paths or by neither — the repeat becomes impossible rather than merely unlikely.

Capture, emission and copying all walk one header-to-field list, so adding a member is one struct field plus one list entry. Nothing else in the emulator enumerates them.

The five sites

Site Behavior
S3Object / S3MultipartUpload one embedded S3SystemMetadata
objectResponseHeaders emits each, only when non-empty
putObject captures via resolveSystemMetadata
createMultipartUpload → completeMultipartUpload recorded on the upload, carried onto the object
resolveCopyMetadata COPY/REPLACE under the existing directive

CopyObject: one directive governs the family

S3 documents a single x-amz-metadata-directive over "the metadata", with no per-header variant, and all four are user-controlled system metadata by the same definition Content-Type and Content-Encoding are. So a REPLACE restating only Content-Type drops the download name a consumer set. That is the failure being modeled, not an implementation shortcut, and it is documented as such — with a test asserting each header is independently restatable but must actually be restated.

Complete accepts no object-metadata headers (the reference lists only the checksum family, x-amz-mp-object-size, request-payer, SSE-C and the conditional headers), so Create is the only place the family can be supplied. A value set at Complete is ignored rather than applied late — pinned by test.

Absent stays absent

An object written without a header produces no header, not an empty one. Cache-Control: and no Cache-Control are different observations, and an SDK distinguishing nil from "" would report the wrong one. Asserted on both read paths, on both write paths, and on the REPLACE drop.

The Expires decision

Stored as a string, never parsed. Real S3 returns what the caller sent; the Go SDK's own GetObject output deprecates its time.Time Expires in favor of ExpiresString — "the unparsed value of the Expires field from the service response". Parsing here would be lower fidelity, and would make a consumer's parse-failure branch unreachable, which is the same vacuous-pass shape this issue is about. A malformed value round-trips unchanged; four value shapes are covered including tomorrow-ish and a non-GMT offset.

Content-Type, Content-Encoding and the storage class stay out of the struct deliberately — each has resolution rules of its own (a default of application/octet-stream, aws-chunked filtering, a STANDARD-means-absent read rule), so folding them in would mean special cases in every helper.

Verified against the model, not from memory

botocore's S3 model confirms all four are location: header members of PutObject, CreateMultipartUpload and CopyObject inputs, and header members of the GetObject/HeadObject outputs — and that CompleteMultipartUpload has none of them on either side. aws-sdk-go-v2/service/[email protected] agrees on the wire names and on the Expires/ExpiresString split.

Headers are read with headerValueFold: an AWSRequest reaching a plugin has not always been through net/http's canonicalization, since substrate builds requests in-process too (betty_cfn.go), and RFC 9110 header names are case-insensitive regardless. The case test drives the plugin directly for that reason — a lowercase header sent through ServeHTTP would arrive canonical and prove nothing.

Tests

27 subtests in the new emulator/s3_system_metadata_test.go, table-driven over the header name so a test cannot pass on one header's behalf: PutObject round-trip on GET and HEAD, per-header isolation, absent-not-emitted, the four Expires shapes, case-insensitivity via the plugin directly, the multipart carry, Complete-headers-ignored, multipart absent, COPY (default and explicit), REPLACE (dropped / restated / per-header), no aliasing between source and copy, survival through a versioned read by versionId, and a ranged 206 carrying the family.

Mutation-tested with six mutants, each caught by the tests that should catch it:

Mutant Caught by
emission removed nearly every test
multipart carry dropped (the #406 shape) MultipartRoundTrip, MultipartCompleteHeadersIgnored
COPY branch drops the family CopyObjectCopyDirective, CopyObjectDoesNotAliasSource
REPLACE branch inherits the source CopyObjectReplaceDirective
empty values emitted as headers the four absent-not-emitted assertions
case-sensitive header read HeaderCaseInsensitive

Docs

New ### Object system metadata section; the ### Copying objects directive table and the multipart carry table both extended; the "not modeled" paragraph removed, which was the issue's last acceptance criterion. Four ops-table rows annotated. All internal anchors verified to resolve.

Verification

gofmt, go build ./..., go vet ./..., golangci-lint run ./... (0 issues), make test (race), test/e2e, make docs-reference-check docs-versions.

@scttfrdmn
scttfrdmn force-pushed the fix/429-sqs-createqueue-errors branch from e88d257 to 8fcd438 Compare August 1, 2026 16:12
@scttfrdmn
scttfrdmn force-pushed the feat/430-s3-system-metadata branch from 3a353ef to 575ba6b Compare August 1, 2026 16:18
@scttfrdmn
scttfrdmn changed the base branch from fix/429-sqs-createqueue-errors to main August 1, 2026 16:18
…e, Expires (#430)

S3Object had no fields for these at all, so substrate accepted the headers on
write and silently discarded them. GetObject and HeadObject never reported them,
which means a consumer asserting that an "attachment; filename=" download name or
a cache lifetime survives an upload got a green test verifying nothing — the write
appeared to succeed. Real S3 persists all three (four, with Expires) as object
metadata and returns them on every read.

All three write paths record the family now: PutObject, CreateMultipartUpload →
CompleteMultipartUpload, and CopyObject.

The four share one embedded struct, S3SystemMetadata, declared once and embedded in
both S3Object and S3MultipartUpload rather than restated. That is the structural
point of the change, not a style preference: the two write paths drifting apart on
a single header is exactly what #406 was, and with one declaration Complete carries
the whole family across in one assignment, so a header added here is carried by both
paths or by neither. Capture, emission and copying all walk one header-to-field list,
so adding a member means one struct field and one list entry.

Complete accepts no object-metadata headers — the reference lists only the checksum
family, x-amz-mp-object-size, request-payer, SSE-C and the conditional headers — so
Create is the only place the family can be supplied, and a value set at Complete is
ignored rather than applied late. Pinned by test.

CopyObject resolves the family under the same x-amz-metadata-directive that already
governed Content-Type and Content-Encoding. S3 documents a single directive over
"the metadata" with no per-header variant, and all four are user-controlled system
metadata by the same definition, so a REPLACE restating only Content-Type drops the
download name a consumer set. That is the failure being modeled, not a shortcut, and
it is documented as such.

An absent header stays absent on the response rather than becoming empty. An SDK
distinguishing nil from "" would otherwise report the wrong one, and "no
Cache-Control" is a different observation from "Cache-Control: ".

Expires is stored as a string and never parsed — the decision the issue asked to
record. Real S3 returns what the caller sent; the Go SDK's own GetObject output
deprecates its time.Time Expires in favor of ExpiresString, "the unparsed value of
the Expires field from the service response". Parsing here would be lower fidelity
and would make a consumer's parse-failure branch unreachable, which is the same
vacuous-pass shape this issue is about. A malformed value round-trips unchanged.

Content-Type, Content-Encoding and the storage class are user-controlled system
metadata too but deliberately stay out of the struct: each has resolution rules of
its own (a default of application/octet-stream, aws-chunked filtering, a
STANDARD-means-absent read rule), so folding them in would mean special cases in
every helper.

Headers are read with headerValueFold, not direct map access: an AWSRequest reaching
a plugin has not always been through net/http's canonicalization, since substrate
builds requests in-process too (betty_cfn.go), and RFC 9110 header names are
case-insensitive regardless. The case test drives the plugin directly for that
reason — a lowercase header sent through ServeHTTP would arrive canonical and prove
nothing.

Mutation-tested with six mutants, each caught by the tests that should catch it:
emission removed, the multipart carry dropped (the #406 shape), the COPY branch
dropping the family, the REPLACE branch wrongly inheriting the source, empty values
emitted as headers, and a case-sensitive header read.

Closes #430
@scttfrdmn
scttfrdmn force-pushed the feat/430-s3-system-metadata branch from 575ba6b to 81905f6 Compare August 1, 2026 16:20
@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 ddd1d6d into main Aug 1, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/430-s3-system-metadata branch August 1, 2026 16:26
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: Cache-Control, Content-Disposition and Content-Language are unmodeled

1 participant