Repository navigation
feat(cli): the gateway answers Range on a sized bundle entry - #2612
Merged
Merged
Conversation
A bundle entry whose manifest declares its size takes one `Range`: `bytes=a-b`, `bytes=a-` or `bytes=-n`. The response is 206 over exactly that window, with `Content-Range` and the window's `Content-Length`, and the pull (`BlobFetch.range`, through `Streamer::open_range`) pays only for the chunk-group-aligned span around the window. The allowance admits and charges the request by that span, so two bytes inside a chunk group cost what the pull pays for them. A range that starts past the end is 416 with the entry's size. A range the gateway cannot honour is ignored, as HTTP allows: several ranges, another unit, a malformed or inverted one, a page rewritten as it streams, a blob whose size nothing declares. A sized response advertises `Accept-Ranges: bytes`, on `HEAD` too, so `curl -r`, a resumed download and a BEP 19 webseed all work. The entry's declared size still caps the pull. Part of #2593. Co-Authored-By: Claude Fable 5.1 <[email protected]>
thiras
force-pushed
the
feat/gateway-range
branch
from
October 24, 2026 18:11
83d17a1 to
0332fe4
Compare
6 tasks done
1 task done
thiras
added a commit
that referenced
this pull request
Oct 24, 2026
…2613) The metrics entry and the `Range` entry (#2612) stand once each. Co-authored-by: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unverified manifest sizes permit allowance undercharging, and conditional and malformed range handling need correction.
3 open issues
What changed in this PR
Adds HTTP byte-range support to the gateway for bundle entries with declared sizes, connecting resumed downloads and webseeds to the client's verified-range streaming.
Changes:
- Returns partial responses for supported ranges and rejects unsatisfiable ranges.
- Passes byte windows into fetch streaming and accounts for aligned spans in the allowance.
- Adds range tests and updates user-facing documentation.
| File | Description |
|---|---|
| docker/README.decdn.md | Documents gateway range support. |
| crates/e2e/tests/gateway_public.rs | Checks range responses through the paid gateway. |
| crates/cli/src/commands/gateway/worker/tests.rs | Updates fetch fixtures with the range field. |
| crates/cli/src/commands/gateway/tests.rs | Tests parsing, headers, range forwarding, and allowance accounting. |
| crates/cli/src/commands/gateway.rs | Implements range handling and aligned-span accounting. |
| crates/cli/src/commands/fetch.rs | Routes byte windows into Streamer::open_range. |
| CHANGELOG.md | Records the new gateway capability. |
Review effort: Balanced
| .saturating_add(len) | ||
| .div_ceil(group) | ||
| .saturating_mul(group) | ||
| .min(size); |
Comment on lines
+2208
to
+2209
| fn range_header(headers: &HeaderMap) -> Option<&str> { | ||
| headers.get(header::RANGE).and_then(|v| v.to_str().ok()) |
Comment on lines
+2249
to
+2263
| if first >= size { | ||
| return Err(()); | ||
| } | ||
| let last = if end.is_empty() { | ||
| size - 1 | ||
| } else { | ||
| let Some(last) = number(end) else { | ||
| return Ok(None); | ||
| }; | ||
| if last < first { | ||
| return Ok(None); | ||
| } | ||
| last.min(size - 1) | ||
| }; | ||
| Ok(Some((first, last - first + 1))) |
Open
7 of 11 tasks
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.


What
The gateway answers HTTP
Rangeon a bundle entry whose manifest declares its size (#2593, thecurl/wgetand BEP 19 webseed shims):bytes=a-b,bytes=a-andbytes=-n→206 Partial Contentover exactly that window, withContent-Range: bytes a-b/sizeand the window'sContent-Length. The pull carries the window (BlobFetch.range) intoStreamer::open_range(feat(client):Streamer::open_rangestreams one verified byte window #2607), so it opens and pays for one leg over the chunk-group-aligned span around the window and nothing else (ADR 038).416withContent-Range: bytes */size, no pull.200: several ranges, another unit, a malformed or inverted range, a page the gateway rewrites as it streams (its length changes), a raw blob whose size nothing declares.Accept-Ranges: bytesonGETandHEAD; an unsized one does not, so a resuming client (huggingface_hubincluded) never sends a range the gateway would answer whole.Extent::billable), with the difference to the window charged when the stream starts. An automated pass on the first push caught that charging the window alone let two-byte ranges pay a 16 KiB group each; two tests pin the span (a_range_is_admitted_by_its_aligned_span,a_range_is_charged_by_its_aligned_span). The entry's declared size still caps the pull (size_cap), and the "delivered whole" check counts the window.Supersedes #2610, which GitHub closed when #2608's merge deleted its base branch; same branch, rebased onto
main. Part of #2593.Reviewer notes
gateway.rs:byte_windowis the whole header grammar;Extentcarries the declared size, the window and whether the response has a fixed length, and replaces thesize: Option<u64>parameter ofstream;Extent::ofdecides honour / ignore / 416 in one place andentry/indexcall it.fetch.rs:BlobFetch.rangeand theopen/open_rangematch instream_out;decdn getsetsrange: Noneeverywhere. Ranges work on the loopback gateway too (same code path); nothing there changes otherwise.Verification
Always:
pre-commit runon commit (all hooks passed;cargo denyfindings are the known warn-only advisories)CARGO_BUILD_WARNINGS=deny cargo clippy -p decdn-cli -p decdn-common -p decdn-e2e --all-targets --all-features: clean (the workspace run was clean on the base; this PR touches those three crates)cargo nextest run -p decdn-cli -p decdn-common -p decdn-e2e: 1514 passedOnly if touched:
cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(gateway_public)'passes with the new step: an off-gridRangereturns 206 and the byte-exact window withContent-Range, andbytes=<size>-returns 416. The client log shows one legbyte_offset=1048576 byte_len=1589248for the 1,572,864-byte window.CHANGELOG.mdentry added by handObservation, not in scope: the node's
decdn_bytes_served_totalreported 3,692,992 for that single 1,589,248-byte leg and 5,275,910 for a whole 4 MiB pull, so its unit is not payload bytes; I dropped the node-side assertion from the e2e rather than encode that.🤖 Generated with Claude Code