Byte-range requests for static files (206 Partial Content)#299
Open
balat wants to merge 4 commits into
Open
Conversation
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).
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
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).header and only the requested bytes (start-end, suffix
-N, and openN-forms).
ETag or Last-Modified.
Where
Response.respond_filegained?range/?if_rangeparameters and theslicing logic (seek + bounded read); Staticmod passes the request headers.
Multi-range requests fall back to a full
200(single range only, as beforethe regression).
Tests
test/range-requests.tchecks Accept-Ranges, a 206 with the rightContent-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.