diff --git a/CHANGES/13580.bugfix.rst b/CHANGES/13580.bugfix.rst new file mode 100644 index 00000000000..62406696f14 --- /dev/null +++ b/CHANGES/13580.bugfix.rst @@ -0,0 +1 @@ +Fixed ``BaseRequest.http_range`` not accepting case-insensitive range units -- by :user:`Manny7717`. diff --git a/CHANGES/13581.bugfix.rst b/CHANGES/13581.bugfix.rst new file mode 120000 index 00000000000..402ff87b6a1 --- /dev/null +++ b/CHANGES/13581.bugfix.rst @@ -0,0 +1 @@ +13580.bugfix.rst \ No newline at end of file diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 3748922ee71..5e8f0e74486 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -258,6 +258,7 @@ Lukasz Marcin Dobrzanski Lukshya Supyal Lénárd Szolnoki Makc Belousow +Manny7717 Manuel Miranda Marat Sharafutdinov Marc Mueller diff --git a/aiohttp/web_request.py b/aiohttp/web_request.py index 5f426d743c7..5938c718a60 100644 --- a/aiohttp/web_request.py +++ b/aiohttp/web_request.py @@ -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] + # https://www.rfc-editor.org/info/rfc9110/#section-14.1-4 + 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") diff --git a/tests/test_web_request.py b/tests/test_web_request.py index d1b6f553a99..760be892f4a 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -316,6 +316,15 @@ def test_range_non_ascii() -> None: req.http_range +def test_range_to_slice_uppercase_unit() -> None: + # https://www.rfc-editor.org/info/rfc9110/#section-14.1-4 + 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