Repository navigation
feat(s3): honor the Range header on GetObject and HeadObject (#396) - #405
Merged
Merged
Conversation
docs/services.md has claimed "GetObject | Supports Range header" since the operation was first documented, but the header was never read: Content-Range, StatusPartialContent and InvalidRange appeared nowhere in non-test source. A consumer whose every read is a ranged GET — a FUSE filesystem, a columnar reader seeking within a Parquet footer — silently received whole objects, so its read-path tests passed while verifying nothing. The edge cases are the substance of the fix, because S3 does not report an error for most bad ranges and a caller cannot use a 416 to detect one. A range past the end of the object is clamped, not rejected. A malformed range, a multi-range request, and a unit other than bytes are all *ignored* — 200 with the whole object. Only a range starting at or beyond the object's end is a 416 InvalidRange, and every range against a zero-byte object is unsatisfiable. byteRangeSpec therefore carries three states rather than a (start, end, error) triple, which cannot distinguish "ignore, serve 200" from "416". Two supporting changes, behavior-preserving except where noted: The error-response builder can now carry error-specific child elements and response headers, which the InvalidRange body needs (<ActualObjectSize>, <RangeRequested>, Content-Range: bytes */<size>) and which MinSizeAllowed (#400) and StorageClass (#398) will need. Its extras ...string parameter was an unused stub with zero call sites, so it is replaced by an s3Error options struct rather than given a meaning; one flat variadic cannot express two independent variable-length things. s3DeleteMarkerResponse shares the builder instead of re-declaring its own XML type. The GET/HEAD header block was duplicated three times and had already drifted, so it moves to objectResponseHeaders and resolveTaskCompletion now returns the object and body it synthesized rather than a finished response. Its clock-gate branch returned a NoSuchKey byte-identical to getObject's own, so that case collapses into handled=false, and a synthesized completion record is rangeable like any other object. Two consequences of de-duplicating, logged as fixes: HEAD now reports x-amz-version-id (GET always did, so a caller had to download a body to learn which version it had just described), and both now advertise Accept-Ranges: bytes. Content-Length is overwritten on a 206 rather than left to the server, which is required and not cosmetic: writeResponse only defaults it when the plugin supplied none, and the header block always supplies the full object size, so a short body would ship under a full-object length and hang SDK clients. A test asserts Content-Length equals the bytes actually written on every 206. The body slice is clamped against the body actually read, because getObject's fallback path can return fewer bytes than the recorded size — that drift already made Content-Length lie, and the clamp keeps it from panicking too. Retrieving a part by ?partNumber=N stays unimplemented; it needs per-part byte boundaries persisted on S3Object, which completeMultipartUpload deletes. Refs #396
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Jul 31, 2026
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.
Closes #396.
docs/services.mdhas claimed| GetObject | Supports Range header |since theoperation was first documented, but the header was never read —
Content-Range,StatusPartialContentandInvalidRangeappeared nowhere in non-test source. Aconsumer whose every read is a ranged GET (the reporter is building a FUSE
filesystem; a columnar reader seeking within a Parquet footer is the same shape)
silently received whole objects, so its read-path tests passed while verifying
nothing. That is the failure mode this repo exists to prevent, and the false doc
claim is what made it invisible.
The edge cases are the substance
S3 does not report an error for most bad ranges, so a caller cannot use a 416 to
detect one. Verified against the AWS GetObject API reference and RFC 9110 §14
rather than from memory:
Range(1000-byte object)bytes=0-99206,Content-Range: bytes 0-99/1000bytes=900-206,bytes 900-999/1000bytes=-100206,bytes 900-999/1000(suffix)bytes=0-99999206, clamped tobytes 0-999/1000— past EOF is not an errorbytes=1000-1099416 InvalidRange+Content-Range: bytes */1000bytes=-0416— a zero-length suffix is unsatisfiablebytes=abc,bytes=500-100200, whole object — malformed ranges are ignoredbytes=0-99,200-299200, whole object — S3 serves one range per GETitems=0-99200, whole object — non-bytesunits ignoredbyteRangeSpectherefore carries three states rather than a(start, end, error)triple, which cannot distinguish "ignore, serve 200" from"416". HEAD honors Range identically, minus the body. Ranges compose with
versionId, and every range against a zero-byte object is unsatisfiable.Two supporting changes
The error builder can now carry child elements and headers. The
InvalidRangebody needs<ActualObjectSize>/<RangeRequested>, and #400(
MinSizeAllowed) and #398 (StorageClass) will need the same. The existingextras ...stringparameter was an unused stub (_ = extras) with zero callsites, so it is replaced by an
s3Erroroptions struct rather than given ameaning — one flat variadic cannot express two independent variable-length things
without a magic sentinel. All 61
s3ErrorResponsecall sites compile untouched,and
s3DeleteMarkerResponsenow shares the builder instead of re-declaring itsown XML type. The dynamic element names rely on
encoding/xmlresolving a namefrom the
XMLNamefield's value ahead of the parent field's tag, so a testasserts the exact XML bytes.
The GET/HEAD header block was duplicated 3× and had already drifted. It moves
to
objectResponseHeaders, andresolveTaskCompletionreturns the object andbody it synthesized rather than a finished response. Its clock-gate branch
returned a
NoSuchKeybyte-identical togetObject's own, so that case collapsesinto
handled=false, and the synthesized completion record becomes rangeable likeany other object. Two behaviour changes fall out, logged under Fixed: HEAD now
reports
x-amz-version-id(GET always did, so a caller had to download a body tolearn which version it had just described), and both now advertise
Accept-Ranges: bytes.The trap worth flagging in review
Content-Lengthis overwritten on a 206 rather than left to the server.server.writeResponseonly defaults Content-Length when the plugin suppliednone, and the object header block always supplies
obj.Size— so a short bodywould ship under a full-object length and hang SDK clients. A test asserts
Content-Lengthequals the bytes actually written on every 206.The body slice is clamped against the body actually read, because
getObject'sfallback path can return fewer bytes than the recorded
Size. That pre-existingdrift already made
Content-Lengthlie; the clamp keeps it from panicking too,rather than papering over it.
Out of scope
Retrieving a part by
?partNumber=Nis unrouted today and needs per-part byteboundaries persisted on
S3Object— whichcompleteMultipartUploadcurrentlydeletes. Noted in the docs as unimplemented; separate issue if wanted.
Verification
go build,go vet,golangci-lint run ./...(0 issues),make test(race),test/e2e, andmake docs-reference-checkall pass locally. Newemulator/s3_range_test.gocovers all 15 table rows above plus theContent-Length desync guard, ETag/Last-Modified identity between 200 and 206,
range+versionId, zero-byte objects, HEAD+Range, case-folded header lookup, a
ranged read of a synthesized completion record, and exact-bytes assertions on the
new error XML.