|
17 | 17 | import aiohttp |
18 | 18 | from aiohttp import http_exceptions, streams |
19 | 19 | from aiohttp.base_protocol import BaseProtocol |
20 | | -from aiohttp.helpers import NO_EXTENSIONS |
| 20 | +from aiohttp.helpers import NO_EXTENSIONS, parse_http_list_values |
21 | 21 | from aiohttp.http_parser import ( |
22 | 22 | DeflateBuffer, |
23 | 23 | HeadersParser, |
@@ -614,6 +614,27 @@ def test_request_te_duplicate_chunked(parser: HttpRequestParser) -> None: |
614 | 614 | parser.feed_data(text) |
615 | 615 |
|
616 | 616 |
|
| 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 | + |
617 | 638 | def test_request_te_empty_list_value_errors_in_py_parser( |
618 | 639 | loop: asyncio.AbstractEventLoop, protocol: BaseProtocol |
619 | 640 | ) -> None: |
|
0 commit comments