|
13 | 13 |
|
14 | 14 | import aiohttp
|
15 | 15 | from aiohttp import http_exceptions, streams
|
| 16 | +from aiohttp.base_protocol import BaseProtocol |
16 | 17 | from aiohttp.http_parser import (
|
17 | 18 | NO_EXTENSIONS,
|
18 | 19 | DeflateBuffer,
|
@@ -1477,7 +1478,55 @@ async def test_parse_chunked_payload_split_chunks(response: Any) -> None:
|
1477 | 1478 | assert await reader.read() == b"firstsecond"
|
1478 | 1479 |
|
1479 | 1480 |
|
1480 |
| -def test_partial_url(parser: Any) -> None: |
| 1481 | +@pytest.mark.skipif(NO_EXTENSIONS, reason="Only tests C parser.") |
| 1482 | +async def test_parse_chunked_payload_with_lf_in_extensions_c_parser( |
| 1483 | + loop: asyncio.AbstractEventLoop, protocol: BaseProtocol |
| 1484 | +) -> None: |
| 1485 | + """Test the C-parser with a chunked payload that has a LF in the chunk extensions.""" |
| 1486 | + # The C parser will raise a BadHttpMessage from feed_data |
| 1487 | + parser = HttpRequestParserC( |
| 1488 | + protocol, |
| 1489 | + loop, |
| 1490 | + 2**16, |
| 1491 | + max_line_size=8190, |
| 1492 | + max_field_size=8190, |
| 1493 | + ) |
| 1494 | + payload = ( |
| 1495 | + b"GET / HTTP/1.1\r\nHost: localhost:5001\r\n" |
| 1496 | + b"Transfer-Encoding: chunked\r\n\r\n2;\nxx\r\n4c\r\n0\r\n\r\n" |
| 1497 | + b"GET /admin HTTP/1.1\r\nHost: localhost:5001\r\n" |
| 1498 | + b"Transfer-Encoding: chunked\r\n\r\n0\r\n\r\n" |
| 1499 | + ) |
| 1500 | + with pytest.raises(http_exceptions.BadHttpMessage, match="\\\\nxx"): |
| 1501 | + parser.feed_data(payload) |
| 1502 | + |
| 1503 | + |
| 1504 | +async def test_parse_chunked_payload_with_lf_in_extensions_py_parser( |
| 1505 | + loop: asyncio.AbstractEventLoop, protocol: BaseProtocol |
| 1506 | +) -> None: |
| 1507 | + """Test the py-parser with a chunked payload that has a LF in the chunk extensions.""" |
| 1508 | + # The py parser will not raise the BadHttpMessage directly, but instead |
| 1509 | + # it will set the exception on the StreamReader. |
| 1510 | + parser = HttpRequestParserPy( |
| 1511 | + protocol, |
| 1512 | + loop, |
| 1513 | + 2**16, |
| 1514 | + max_line_size=8190, |
| 1515 | + max_field_size=8190, |
| 1516 | + ) |
| 1517 | + payload = ( |
| 1518 | + b"GET / HTTP/1.1\r\nHost: localhost:5001\r\n" |
| 1519 | + b"Transfer-Encoding: chunked\r\n\r\n2;\nxx\r\n4c\r\n0\r\n\r\n" |
| 1520 | + b"GET /admin HTTP/1.1\r\nHost: localhost:5001\r\n" |
| 1521 | + b"Transfer-Encoding: chunked\r\n\r\n0\r\n\r\n" |
| 1522 | + ) |
| 1523 | + messages, _, _ = parser.feed_data(payload) |
| 1524 | + reader = messages[0][1] |
| 1525 | + assert isinstance(reader.exception(), http_exceptions.BadHttpMessage) |
| 1526 | + assert "\\nxx" in str(reader.exception()) |
| 1527 | + |
| 1528 | + |
| 1529 | +def test_partial_url(parser: HttpRequestParser) -> None: |
1481 | 1530 | messages, upgrade, tail = parser.feed_data(b"GET /te")
|
1482 | 1531 | assert len(messages) == 0
|
1483 | 1532 | messages, upgrade, tail = parser.feed_data(b"st HTTP/1.1\r\n\r\n")
|
|
0 commit comments