Skip to content

feat(cli): the gateway answers Range on a sized bundle entry - #2612

Merged
thiras merged 1 commit into
mainfrom
feat/gateway-range
Oct 24, 2026
Merged

thiras merged 1 commit into
mainfrom
feat/gateway-range

Conversation

@thiras

@thiras thiras commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

What

The gateway answers HTTP Range on a bundle entry whose manifest declares its size (#2593, the curl/wget and BEP 19 webseed shims):

  • bytes=a-b, bytes=a- and bytes=-n → 206 Partial Content over exactly that window, with Content-Range: bytes a-b/size and the window's Content-Length. The pull carries the window (BlobFetch.range) into Streamer::open_range (feat(client): Streamer::open_range streams 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).
  • A range starting at or past the end → 416 with Content-Range: bytes */size, no pull.
  • A range the gateway cannot honour is ignored as HTTP allows and the whole body is served as 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.
  • A sized response advertises Accept-Ranges: bytes on GET and HEAD; an unsized one does not, so a resuming client (huggingface_hub included) never sends a range the gateway would answer whole.
  • The allowance admits and charges a range by the span the pull pays for: the window widened to whole chunk groups, clipped to the entry (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_window is the whole header grammar; Extent carries the declared size, the window and whether the response has a fixed length, and replaces the size: Option<u64> parameter of stream; Extent::of decides honour / ignore / 416 in one place and entry/index call it. fetch.rs: BlobFetch.range and the open/open_range match in stream_out; decdn get sets range: None everywhere. Ranges work on the loopback gateway too (same code path); nothing there changes otherwise.

Verification

Always:

  • pre-commit run on commit (all hooks passed; cargo deny findings 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 passed
  • PR title uses an allowed type and the subject does not start with an uppercase letter

Only if touched:

  • anvil e2e: cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(gateway_public)' passes with the new step: an off-grid Range returns 206 and the byte-exact window with Content-Range, and bytes=<size>- returns 416. The client log shows one leg byte_offset=1048576 byte_len=1589248 for the 1,572,864-byte window.
  • CHANGELOG.md entry added by hand

Observation, not in scope: the node's decdn_bytes_served_total reported 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

@thiras thiras added kind:feature New capability or a change to current behavior area:cli decdn binary: get, gateway, pool, publish, origin, setup labels Oct 24, 2026
Copilot AI balanced review requested due to automatic review settings October 24, 2026 18:11
@thiras thiras added kind:feature New capability or a change to current behavior area:cli decdn binary: get, gateway, pool, publish, origin, setup labels Oct 24, 2026
@thiras thiras self-assigned this Oct 24, 2026
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
thiras force-pushed the feat/gateway-range branch from 83d17a1 to 0332fe4 Compare October 24, 2026 18:11
@thiras
thiras merged commit 4ffedb6 into main Oct 24, 2026
1 check passed
@thiras
thiras deleted the feat/gateway-range branch October 24, 2026 18:11
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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli decdn binary: get, gateway, pool, publish, origin, setup kind:feature New capability or a change to current behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants