[PR #13581/9c77642c backport][3.15] Accept case-insensitive range unit names in http_range by patchback[bot] · Pull Request #13588 · aio-libs/aiohttp · GitHub
Skip to content

[PR #13581/9c77642c backport][3.15] Accept case-insensitive range unit names in http_range - #13588

Merged
Dreamsorcerer merged 1 commit into
3.15from
patchback/backports/3.15/9c77642ce54c836017961ff1908c3ff2dc934615/pr-13581
Aug 31, 2026
Merged

Dreamsorcerer merged 1 commit into
3.15from
patchback/backports/3.15/9c77642ce54c836017961ff1908c3ff2dc934615/pr-13581

Conversation

@patchback

@patchback patchback Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

This is a backport of PR #13581 as merged into master (9c77642).

What do these changes do?

BaseRequest.http_range now 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-499 failed the ^bytes=(\d*)-(\d*)$ regex, raising ValueError("range not in acceptable format"), which FileResponse converts into 416 Requested Range Not Satisfiable — even for a perfectly satisfiable range. Only lowercase bytes= 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 yield 206 Partial Content where lowercase already did. Behavior for lowercase bytes= and for genuinely malformed ranges (non-bytes units, non-numeric bounds, multi-range, empty) is unchanged — those still raise the same ValueError.

Is it a substantial burden for the maintainers to support this?

No. One regex flag; no API surface change; the pure-Python http_range property is the only code path touched. FileResponse consumes it, so the fix propagates automatically.

Related issue number

Fixes #13580

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes (N/A — bug fix, no user-facing docs to update; CHANGES fragment added)
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is .
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)
    • if you don't have an issue number, change it to the pull request number after creating the PR
    • .bugfix: A bug fix for something the maintainers deemed an improper undesired behavior that got corrected to match pre-agreed expectations.
Test output
$ python -m pytest -o addopts="" -p no:aiohttp tests/test_web_request.py -q
143 passed in 0.68s

(10 of those are the http_range/range parsing tests, including the new test_range_to_slice_uppercase_unit.)

End-to-end repro (local web.FileResponse server, raw TCP requests):

Range: bytes=0-3   -> HTTP/1.1 206 Partial Content      (control)
Range: Bytes=0-3   -> HTTP/1.1 206 Partial Content      (fixed; was 416)
Range: BYTES=0-3   -> HTTP/1.1 206 Partial Content      (fixed; was 416)

Drafted with Hermes Agent (deepseek-v4-flash); reviewed by Manny7717.

@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Comment thread aiohttp/web_request.py
@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.27%. Comparing base (4202a9c) to head (ea07649).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             3.15   #13588      +/-   ##
==========================================
+ Coverage   96.19%   96.27%   +0.07%     
==========================================
  Files         161      161              
  Lines       51905    51909       +4     
  Branches     2852     2852              
==========================================
+ Hits        49932    49977      +45     
+ Misses       1781     1752      -29     
+ Partials      192      180      -12     
Flag Coverage Δ
CI-GHA 96.23% <100.00%> (+0.06%) ⬆️
OS-Linux 96.01% <100.00%> (+0.06%) ⬆️
OS-Windows 93.80% <100.00%> (+0.26%) ⬆️
OS-macOS 95.23% <100.00%> (+0.33%) ⬆️
Py-3.10 95.35% <100.00%> (+0.39%) ⬆️
Py-3.11 95.60% <100.00%> (+0.18%) ⬆️
Py-3.12 95.68% <100.00%> (-0.01%) ⬇️
Py-3.13 95.67% <100.00%> (?)
Py-3.14 95.78% <100.00%> (+0.02%) ⬆️
Py-3.14t 94.86% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 94.64% <100.00%> (?)
VM-macos 95.23% <100.00%> (+0.33%) ⬆️
VM-ubuntu 96.01% <100.00%> (+0.06%) ⬆️
VM-windows 93.80% <100.00%> (+0.26%) ⬆️
cython-coverage 79.04% <0.00%> (+<0.01%) ⬆️

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

codspeed Bot commented Aug 31, 2026

Copy link
Copy Markdown

@Dreamsorcerer
Dreamsorcerer merged commit 16b630a into 3.15 Aug 31, 2026
49 checks passed
@Dreamsorcerer
Dreamsorcerer deleted the patchback/backports/3.15/9c77642ce54c836017961ff1908c3ff2dc934615/pr-13581 branch August 31, 2026 00:43
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.

2 participants