Accept case-insensitive range unit names in http_range by Manny7717 · Pull Request #13581 · aio-libs/aiohttp · GitHub
Skip to content

Accept case-insensitive range unit names in http_range - #13581

Merged
Dreamsorcerer merged 3 commits into
aio-libs:masterfrom
Manny7717:fix/http-range-case-insensitive
Aug 31, 2026
Merged

Dreamsorcerer merged 3 commits into
aio-libs:masterfrom
Manny7717:fix/http-range-case-insensitive

Conversation

@Manny7717

Copy link
Copy Markdown
Contributor

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.

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.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Aug 29, 2026
@codecov

codecov Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

@codspeed

codspeed Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 96 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing Manny7717:fix/http-range-case-insensitive (f51f000) 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. ↩

@Manny7717
Manny7717 marked this pull request as ready for review August 29, 2026 04:19
@greptile-apps

greptile-apps Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "Apply batched suggestions from code revi..." | Re-trigger Greptile

Comment thread aiohttp/web_request.py Outdated
Comment thread CHANGES/13580.bugfix.rst Outdated
Comment thread tests/test_web_request.py Outdated
Co-authored-by: Sam Bull <aa6bs0@sambull.org>
@Dreamsorcerer Dreamsorcerer added backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot labels Aug 30, 2026
@Dreamsorcerer
Dreamsorcerer merged commit 9c77642 into aio-libs:master Aug 31, 2026
53 of 54 checks passed
@patchback

patchback Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Backport to 3.15: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.15/9c77642ce54c836017961ff1908c3ff2dc934615/pr-13581

Backported as #13588

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Dreamsorcerer pushed a commit that referenced this pull request Aug 31, 2026
…t names in http_range (#13588)

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

Co-authored-by: Walter Gaalswyk <166943092+Manny7717@users.noreply.github.com>
Dreamsorcerer pushed a commit that referenced this pull request Aug 31, 2026
…t names in http_range (#13589)

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

Co-authored-by: Walter Gaalswyk <166943092+Manny7717@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot 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)

2 participants