Skip to content

Store an S3 object's Content-Type and x-amz-meta-* headers with its key - #189

Merged
saworbit merged 1 commit into
mainfrom
fix/s3-object-metadata
Nov 14, 2026
Merged

saworbit merged 1 commit into
mainfrom
fix/s3-object-metadata

Conversation

@saworbit

Copy link
Copy Markdown
Owner

Fixes #163

  • An S3 PUT stores Content-Type, Content-Disposition, Content-Encoding, Content-Language, Cache-Control, Expires and x-amz-meta-*. GET, ranged GET and HEAD return them. A response-* parameter still overrides the header it names. An overwrite replaces the metadata.
  • The headers go in the key's BIND record, so they commit with the key and survive restarts, index rebuilds and journal compaction. BIND is now layout version 2: after name, a count and that many key and value strings (on-disk format §5.6). A version 1 BIND still reads, as a name with no metadata.
  • The index keeps the metadata next to the capsule id. INDEX_VERSION goes to 3, so an existing store rebuilds its index from the journal once, on first open.
  • As in S3, the x-amz-meta-* names and values can add up to 2 KB, or the PUT gets MetadataTooLarge. A header value that isn't ASCII gets InvalidArgument. Both are checked before the body is stored.
  • Without a Content-Type, the type is guessed from the extension as before, now ignoring case and knowing more types (.svg, .csv, .mp4, .wasm, .gz and others). I kept the table instead of adding mime_guess, since most clients send a type.
  • S3View::put_object_if becomes put_object_with, which takes a PutOptions with the conditions and the metadata.

Compatibility: a build from before this refuses a store that holds a version 2 BIND. It fails closed, like the KEY record from #186.

Tests: HTTP tests cover the stored headers on HEAD, GET and ranged GET, overrides, overwrite, the extension guess, the 2 KB limit (data log unchanged on refusal) and non-ASCII values. Lifecycle tests cover a restart and a lost index, and metadata that can't be stored. The journal compaction tests now bind with metadata, so they check it survives compaction and rebuilds. Ten mutants each fail a test: decode, compaction or the index dropping metadata, the PUT keeping no headers, GET and HEAD sending none, the stored type ignored, no size limit, any name stored, non-ASCII stored, and case-sensitive extensions. I ran the issue's boto3 repro against serve-s3: image/jpeg and {'owner': 'qa'} come back.

While doing this I found #188: after journal compaction, a rebuilt index can hold dedup entries the live index dropped. It was already on main, and it's separate from this change.

Docs: CHANGELOG, on-disk-format §5.6 and §7, QUICKSTART_S3.

An S3 PUT keeps Content-Type, Content-Disposition, Content-Encoding,
Content-Language, Cache-Control, Expires and x-amz-meta-*, and GET and HEAD
return them. They go in the key's BIND record, now layout version 2, so
they survive restarts, index rebuilds and compaction. User metadata over
2 KB is refused with MetadataTooLarge. Without a Content-Type the type is
guessed from the extension, now ignoring case and knowing more types.

Fixes #163
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.

[Gap] S3 PUT drops Content-Type and x-amz-meta-*; type is guessed from a case-sensitive extension list

1 participant