Skip to content

Commit 8e8bc9e

Browse files
Refine scoped header list parsing follow-up
1 parent 760f48b commit 8e8bc9e

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

CHANGES/12249.bugfix.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Normalized parsing of list-style ``Connection`` and ``Transfer-Encoding``
2+
headers in the pure-Python HTTP parser so repeated field lines and
3+
comma-joined values are handled consistently for keep-alive, close,
4+
upgrade, and chunked detection.
5+
-- by :user:`rodrigobnogueira`.

CHANGES/12253.bugfix.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Normalized parsing of list-style ``Connection`` and ``Transfer-Encoding``
2-
headers in the pure-Python HTTP parser so repeated field lines and
3-
comma-joined values are handled consistently for keep-alive, close,
4-
upgrade, and chunked detection.
1+
Added ``parse_http_list_values()`` to normalize repeated and comma-joined
2+
list-style header values, and used it for ``Connection`` and
3+
``Transfer-Encoding`` handling in the pure-Python HTTP parser.
54
-- by :user:`rodrigobnogueira`.

tests/test_http_parser.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import aiohttp
1818
from aiohttp import http_exceptions, streams
1919
from aiohttp.base_protocol import BaseProtocol
20-
from aiohttp.helpers import NO_EXTENSIONS
20+
from aiohttp.helpers import NO_EXTENSIONS, parse_http_list_values
2121
from aiohttp.http_parser import (
2222
DeflateBuffer,
2323
HeadersParser,
@@ -614,6 +614,27 @@ def test_request_te_duplicate_chunked(parser: HttpRequestParser) -> None:
614614
parser.feed_data(text)
615615

616616

617+
@pytest.mark.parametrize(
618+
("header_lines", "expected"),
619+
[
620+
(b"Foo: 1\r\nFoo: 2\r\n", ("1", "2")),
621+
(b"Foo: 1, 2\r\n", ("1", "2")),
622+
(
623+
b'Foo: "http://example.com/a.html,foo", apples\r\n',
624+
('"http://example.com/a.html,foo"', "apples"),
625+
),
626+
],
627+
)
628+
def test_parse_http_list_values_normalizes_parser_header_views(
629+
parser: HttpRequestParser, header_lines: bytes, expected: tuple[str, ...]
630+
) -> None:
631+
text = b"GET /test HTTP/1.1\r\n" + header_lines + b"\r\n"
632+
messages, upgrade, tail = parser.feed_data(text)
633+
msg = messages[0][0]
634+
635+
assert parse_http_list_values(msg.headers.getall("Foo", ())) == expected
636+
637+
617638
def test_request_te_empty_list_value_errors_in_py_parser(
618639
loop: asyncio.AbstractEventLoop, protocol: BaseProtocol
619640
) -> None:

0 commit comments

Comments
 (0)