Repository navigation
Conversation
FileResponse only implements a single byte range. A Range header with multiple byte-range-specs (for example bytes=0-1,4-5) made http_range raise ValueError, and every ValueError was turned into 416. A satisfiable multi-range set must not get 416; ignore Range and return the full file as 200 instead (RFC 9110 §14.2). Malformed ranges still get 416. Fixes aio-libs#14124.
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #14129 +/- ##
=======================================
Coverage 99.13% 99.13%
=======================================
Files 135 135
Lines 54630 54657 +27
Branches 2808 2809 +1
=======================================
+ Hits 54158 54185 +27
Misses 357 357
Partials 115 115
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Confidence Score: 4/5
[Medium impact] The change affects clients receiving files through `FileResponse`. Not ready to merge: valid spaced range lists still return Reviews (17) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile |
| # single range; a satisfiable multi-range must not become 416 (RFC 9110 §14.2 | ||
| # allows ignoring Range and returning 200 with the full representation). | ||
| _MULTI_BYTE_RANGE_RE = re.compile( | ||
| r"^bytes=(?:\d+-\d*|-\d+)(?:,(?:\d+-\d*|-\d+))+$", |
There was a problem hiding this comment.
A valid header such as Range: bytes=0-1, 4-5 still gets 416 for a file with at least six bytes. HTTP list syntax allows spaces or tabs around commas, but this pattern rejects them. Clients using that spacing still get an error instead of the full file. Allow that whitespace and add a regression test.
Knowledge Base Used: Server routing, responses, and static files
| if range_hdr is not None and _MULTI_BYTE_RANGE_RE.fullmatch(range_hdr): | ||
| pass |
There was a problem hiding this comment.
Backwards ranges download full files
The pattern matches bytes=100-0,0-1, although its first range runs backwards. The new fallback returns 200 with the full file instead of the previous 416, contrary to the promised unchanged behavior for malformed ranges. Check each bounded range's start and end before accepting the set, and add a regression test.
Knowledge Base Used: Server routing, responses, and static files
| Fixed ``FileResponse`` answering a well-formed multi-range request with | ||
| ``416 Range Not Satisfiable`` instead of ignoring ``Range`` and returning the | ||
| full file -- by :user:`vyrnsynx`. |
There was a problem hiding this comment.
Required release updates are missing
AGENTS.md requires docs for user-visible API changes and news entries under both the issue and PR numbers. This status-code change has no docs/ update and only the issue-numbered fragment. Before merging, document the new behavior under FileResponse and add CHANGES/14129.bugfix.rst as a symlink to 14124.bugfix.rst.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Initialize start/end before parsing http_range so ignoring a well-formed multi-range header can fall through to a full 200 without leaving those names unbound for mypy.
start is already declared at the top of _prepare_open_file; only end needed a matching None default so the multi-range ignore path stays typed without redefining start.
…multi-range-14124
…multi-range-14124
…multi-range-14124
…multi-range-14124 Signed-off-by: vyrnsynx <153433026+vyrnsynx@users.noreply.github.com>
…multi-range-14124
…multi-range-14124
…multi-range-14124 Signed-off-by: vyrnsynx <153433026+vyrnsynx@users.noreply.github.com>
…multi-range-14124 Signed-off-by: vyrnsynx <153433026+vyrnsynx@users.noreply.github.com>
…multi-range-14124 Signed-off-by: vyrnsynx <153433026+vyrnsynx@users.noreply.github.com>
…multi-range-14124
…multi-range-14124
…multi-range-14124
…multi-range-14124
What do these changes do?
BaseRequest.http_rangeonly accepts a single byte range, so a header likeRange: bytes=0-1,4-5raisesValueError.FileResponse._prepare_open_fileturned every such
ValueErrorinto416withContent-Range: bytes */N.A multi-range set can still be satisfiable. RFC 9110 §14.2 lets a server ignore
Rangeand send200with the full representation; the comment already nextto the 416 path quotes the same idea from RFC 7233. This change recognises a
well-formed multi-range set and falls through to a full
200instead of 416.Malformed ranges (
bytes=a-f,bytes=100-0,bytes=0-1,a-b, …) are unchanged.http_rangeitself stays single-range on purpose (same choice as #2805).Are there changes in behavior for the user?
Yes, intentional:
Range: bytes=0-1,4-5(and other well-formed multi-rangesets) against
FileResponsenow returns200with the full body instead of416. Single-range and malformedRangebehaviour is unchanged. Amultipart/byteranges206 would also be valid; ignoring the header is thesmaller change.
Is it a substantial burden for the maintainers to support this?
No. One regex check on the existing
ValueErrorpath; no new public API;http_rangestays single-range.Related issue number
Fixes #14124.
Checklist
CONTRIBUTORS.txtCHANGES/folder14124.bugfix.rst