Multipart download enhancements#4021
Conversation
Blob HEAD responses had no Content-Type and GET responses echoed the request's Accept header verbatim, which produced missing or malformed media types and left multipart/byteranges parts without a per-part Content-Type. This breaks OCI distribution-spec conformance and consumers like stargz-snapshotter that need a well-formed layer media type. Add a blobResponseMediaType helper that resolves the descriptor's MediaType via GetBlobDescriptorFromRepo and falls back to application/octet-stream. Use it in CheckBlob (HEAD), GetBlob full (200), GetBlob single-range (206), and per-part in writeMultipartRanges (206 multipart). Lookup is deferred until after the blob is known to exist. Cover the new behaviour with mock-based unit tests in routes_test.go and end-to-end assertions in TestPullRange. Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
There was a problem hiding this comment.
Pull request overview
Follow-up to earlier multipart range blob pull work, improving blob download responses to be descriptor-aware for Content-Type and optimizing multipart range delivery to reduce concurrent reader usage.
Changes:
- Add descriptor-aware
Content-Typeresolution for blob HEAD/GET withapplication/octet-streamfallback. - Rework multipart range responses to stream ranges lazily (one reader at a time) and advertise a precomputed
Content-Length. - Expand test coverage for descriptor-derived
Content-Type, multipart part headers, streaming behavior, and truncation on mid-stream read errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/api/routes.go | Adds blobResponseMediaType, sets Content-Type for blob responses, and rewrites multipart range streaming to be lazy with precomputed Content-Length. |
| pkg/api/routes_test.go | Adds unit tests for descriptor-aware Content-Type and multipart range response behavior (per-part headers, content-length correctness, sequential reader opens, truncation on error). |
| pkg/api/controller_test.go | Extends existing range-pull integration tests to assert correct fallback/per-part Content-Type behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4021 +/- ##
==========================================
+ Coverage 91.39% 91.48% +0.09%
==========================================
Files 197 197
Lines 28308 28353 +45
==========================================
+ Hits 25872 25940 +68
+ Misses 1581 1561 -20
+ Partials 855 852 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d552e1a to
e96ba0a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…nt-Length writeMultipartRanges previously opened every range reader up front and emitted no Content-Length, so an N-range request held N concurrent storage readers (and their fds / read buffers) per response window and forced chunked encoding on HTTP/1.1 — neither friendly to proxies nor to fan-out scenarios like stargz lazy pulls. Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
code coverage is dropping and trending in the wrong direction :( |
| // distribution-spec conformance and consumers like stargz-snapshotter that | ||
| // require a non-empty, well-formed media type. |
There was a problem hiding this comment.
nit: specific tools probably shouldn't be mentioned in the source code as the implementation is aligned to dist-spec.
| // distribution-spec conformance and consumers like stargz-snapshotter that | |
| // require a non-empty, well-formed media type. | |
| // distribution-spec conformance that | |
| // requires a non-empty, well-formed media type. |

As a follow-up to #3995, to include enhancements in #3976
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.