Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES/13580.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed ``BaseRequest.http_range`` rejecting valid case-insensitive range
unit names (e.g. ``Range: Bytes=0-499``), which made ``FileResponse``
return ``416 Requested Range Not Satisfiable`` for satisfiable ranges
-- by :user:`Manny7717`.
1 change: 1 addition & 0 deletions CHANGES/13581.bugfix.rst
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ Lukasz Marcin Dobrzanski
Lukshya Supyal
Lénárd Szolnoki
Makc Belousow
Manny7717
Manuel Miranda
Marat Sharafutdinov
Marc Mueller
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ def http_range(self) -> "slice[int, int, int]":
if rng is not None:
try:
pattern = r"^bytes=(\d*)-(\d*)$"
start, end = re.findall(pattern, rng, re.ASCII)[0]
# Range unit names are case-insensitive (RFC 9110 §14.1.1).
start, end = re.findall(pattern, rng, re.ASCII | re.IGNORECASE)[0]
except IndexError: # pattern was not found in header
raise ValueError("range not in acceptable format")

Expand Down
9 changes: 9 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ def test_range_non_ascii() -> None:
req.http_range


def test_range_to_slice_uppercase_unit() -> None:
# Range unit names are case-insensitive (RFC 9110 §14.1.1).
req = make_mocked_request(
"GET", "/", headers=CIMultiDict([("RANGE", "Bytes=0-499")])
)
assert isinstance(req.http_range, slice)
assert req.http_range.start == 0 and req.http_range.stop == 500


def test_non_keepalive_on_http10() -> None:
req = make_mocked_request("GET", "/", version=HttpVersion(1, 0))
assert not req.keep_alive
Expand Down
Loading