Skip to content

Byte-range requests for static files (206 Partial Content)#299

Open
balat wants to merge 4 commits into
qw2-conditional-requestsfrom
qw3-range-requests
Open

Byte-range requests for static files (206 Partial Content)#299
balat wants to merge 4 commits into
qw2-conditional-requestsfrom
qw3-range-requests

Conversation

@balat

@balat balat commented Jun 26, 2026

Copy link
Copy Markdown
Member

What

Static files now support single byte-range requests (RFC 7233), enabling media
streaming and resumable downloads — a feature that regressed in the cohttp
migration (there was a TODO: equivalent of Ocsigen_range).

  • Responses advertise Accept-Ranges: bytes.
  • A satisfiable Range yields 206 Partial Content with a Content-Range
    header and only the requested bytes (start-end, suffix -N, and open N-
    forms).
  • An unsatisfiable range gives 416.
  • The range is honoured only when If-Range (if present) matches the current
    ETag or Last-Modified.

Where

Response.respond_file gained ?range / ?if_range parameters and the
slicing logic (seek + bounded read); Staticmod passes the request headers.
Multi-range requests fall back to a full 200 (single range only, as before
the regression).

Tests

test/range-requests.t checks Accept-Ranges, a 206 with the right
Content-Range and body, suffix and open-ended ranges, a 416 for an
unsatisfiable range, and that a non-matching If-Range serves the whole file.

Note

Stacked on #298 (conditional requests) since both build on
Response.respond_file; base will retarget to master once #298 merges.

balat added 4 commits June 26, 2026 13:24
Response.respond_file now advertises Accept-Ranges and takes optional [range]
and [if_range] values. A satisfiable single byte range is returned as
206 Partial Content with a Content-Range header and only the requested bytes;
an unsatisfiable range gives 416. The range is honoured only when If-Range (if
present) matches the current validators (RFC 7233).
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.

1 participant