Accept case-insensitive range unit names in http_range - #13581
Conversation
Range unit names are case-insensitive per RFC 9110 section 14.1.1. The previous regex only matched lowercase 'bytes', so valid headers like 'Range: Bytes=0-499' raised ValueError and made FileResponse return 416 for satisfiable ranges.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13581 +/- ##
=======================================
Coverage 99.02% 99.02%
=======================================
Files 135 135
Lines 50500 50504 +4
Branches 2652 2652
=======================================
+ Hits 50007 50011 +4
Misses 370 370
Partials 123 123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness, compatibility, or security issues identified. The regex flag affects only the casing of the literal Reviews (1): Last reviewed commit: "Add PR-numbered news fragment symlink" | Re-trigger Greptile |
What do these changes do?
BaseRequest.http_rangenow matches the range unit name case-insensitively (re.IGNORECASE), per RFC 9110 §14.1.1 ("All range unit names are case-insensitive").Previously a valid header like
Range: Bytes=0-499failed the^bytes=(\d*)-(\d*)$regex, raisingValueError("range not in acceptable format"), whichFileResponseconverts into416 Requested Range Not Satisfiable— even for a perfectly satisfiable range. Only lowercasebytes=worked.Are there changes in behavior for the user?
Yes, for the better: case variants of the range unit (
Bytes,BYTES,bYtEs, …) are now accepted and yield206 Partial Contentwhere lowercase already did. Behavior for lowercasebytes=and for genuinely malformed ranges (non-bytesunits, non-numeric bounds, multi-range, empty) is unchanged — those still raise the sameValueError.Is it a substantial burden for the maintainers to support this?
No. One regex flag; no API surface change; the pure-Python
http_rangeproperty is the only code path touched.FileResponseconsumes it, so the fix propagates automatically.Related issue number
Fixes #13580
Checklist
CONTRIBUTORS.txtCHANGES/folder<issue_or_pr_num>.<type>.rst(e.g.588.bugfix.rst).bugfix: A bug fix for something the maintainers deemed an improper undesired behavior that got corrected to match pre-agreed expectations.Test output
(10 of those are the
http_range/range parsing tests, including the newtest_range_to_slice_uppercase_unit.)End-to-end repro (local
web.FileResponseserver, raw TCP requests):Drafted with Hermes Agent (deepseek-v4-flash); reviewed by Manny7717.