Skip to content

Accept case-insensitive range unit names in Range header - #13585

Open
afonsojanu wants to merge 1 commit into
aio-libs:masterfrom
afonsojanu:fix/http-range-case-insensitive-unit-13580
Open

Accept case-insensitive range unit names in Range header#13585
afonsojanu wants to merge 1 commit into
aio-libs:masterfrom
afonsojanu:fix/http-range-case-insensitive-unit-13580

Conversation

@afonsojanu

Copy link
Copy Markdown

Closes #13580.

RFC 9110 section 14.1.1 states that range unit names are case-insensitive, but the regex used to parse the Range header only matched a lowercase bytes literal:

pattern = r"^bytes=(\d*)-(\d*)$"
start, end = re.findall(pattern, rng, re.ASCII)[0]

A request sent with any other casing, such as Range: Bytes=0-3 or Range: BYTES=0-3, raised ValueError("range not in acceptable format"), which FileResponse turns into a 416 response even though the range itself is perfectly satisfiable.

Added re.IGNORECASE to the existing pattern match flags and a regression test alongside the existing range-parsing tests, covering an uppercase-initial unit name. Ran the full test_web_request.py suite plus flake8 on the touched files.

RFC 9110 section 14.1.1 states that range unit names are
case-insensitive, but the regex used to parse the Range header only
matched a lowercase 'bytes' literal. A request sent with any other
casing, such as 'Bytes=0-3' or 'BYTES=0-3', raised a ValueError that
FileResponse turned into a 416 response even though the range itself
was perfectly valid.

Added re.IGNORECASE to the existing pattern match and a regression
test covering an uppercase-initial unit name alongside the existing
lowercase and non-ASCII cases.

Fixes aio-libs#13580
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Aug 29, 2026
@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness, compatibility, or security issues identified.

The parser remains anchored to the bytes unit and ASCII digits, while the only behavioral expansion is accepting RFC-compliant ASCII case variants; existing invalid-input and FileResponse error behavior remain intact.

Reviews (1): Last reviewed commit: "Accept case-insensitive range unit names..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (20acdf4) to head (0393b9e).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13585   +/-   ##
=======================================
  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           
Flag Coverage Δ
Autobahn 22.03% <20.00%> (+<0.01%) ⬆️
CI-GHA 98.91% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.68% <100.00%> (+<0.01%) ⬆️
OS-Windows 97.09% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.96% <100.00%> (-0.01%) ⬇️
Py-3.10 98.11% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.34% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.43% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.41% <100.00%> (-0.01%) ⬇️
Py-3.14 98.44% <100.00%> (-0.01%) ⬇️
Py-3.14t 97.60% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 97.40% <100.00%> (+0.01%) ⬆️
VM-macos 97.96% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.68% <100.00%> (+<0.01%) ⬆️
VM-windows 97.09% <100.00%> (+<0.01%) ⬆️
cython-coverage 83.07% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Aug 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 96 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing afonsojanu:fix/http-range-case-insensitive-unit-13580 (0393b9e) with master (20acdf4)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http_range rejects valid case-insensitive range unit names (Range: Bytes=… → 416)

1 participant