From 64840f491a706cea83ff18fc04a1f3e747d313f1 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 21 Apr 2024 12:52:34 +0100 Subject: [PATCH] Remove unused readall from Python parser (#8096) (cherry picked from commit 175954c010eb2446fe43c3167cdca671a4079e53) --- aiohttp/http_parser.py | 20 +------------------- tests/test_http_parser.py | 35 +++++++++-------------------------- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/aiohttp/http_parser.py b/aiohttp/http_parser.py index 013511917e8..751a7e1bb73 100644 --- a/aiohttp/http_parser.py +++ b/aiohttp/http_parser.py @@ -47,7 +47,6 @@ TransferEncodingError, ) from .http_writer import HttpVersion, HttpVersion10 -from .log import internal_logger from .streams import EMPTY_PAYLOAD, StreamReader from .typedefs import RawHeaders @@ -249,7 +248,6 @@ def __init__( timer: Optional[BaseTimerContext] = None, code: Optional[int] = None, method: Optional[str] = None, - readall: bool = False, payload_exception: Optional[Type[BaseException]] = None, response_with_body: bool = True, read_until_eof: bool = False, @@ -263,7 +261,6 @@ def __init__( self.timer = timer self.code = code self.method = method - self.readall = readall self.payload_exception = payload_exception self.response_with_body = response_with_body self.read_until_eof = read_until_eof @@ -393,7 +390,6 @@ def get_content_length() -> Optional[int]: method=method, compression=msg.compression, code=self.code, - readall=self.readall, response_with_body=self.response_with_body, auto_decompress=self._auto_decompress, lax=self.lax, @@ -413,7 +409,6 @@ def get_content_length() -> Optional[int]: payload, method=msg.method, compression=msg.compression, - readall=True, auto_decompress=self._auto_decompress, lax=self.lax, ) @@ -431,7 +426,6 @@ def get_content_length() -> Optional[int]: method=method, compression=msg.compression, code=self.code, - readall=True, response_with_body=self.response_with_body, auto_decompress=self._auto_decompress, lax=self.lax, @@ -751,13 +745,12 @@ def __init__( compression: Optional[str] = None, code: Optional[int] = None, method: Optional[str] = None, - readall: bool = False, response_with_body: bool = True, auto_decompress: bool = True, lax: bool = False, ) -> None: self._length = 0 - self._type = ParseState.PARSE_NONE + self._type = ParseState.PARSE_UNTIL_EOF self._chunk = ChunkState.PARSE_CHUNKED_SIZE self._chunk_size = 0 self._chunk_tail = b"" @@ -779,7 +772,6 @@ def __init__( self._type = ParseState.PARSE_NONE real_payload.feed_eof() self.done = True - elif chunked: self._type = ParseState.PARSE_CHUNKED elif length is not None: @@ -788,16 +780,6 @@ def __init__( if self._length == 0: real_payload.feed_eof() self.done = True - else: - if readall and code != 204: - self._type = ParseState.PARSE_UNTIL_EOF - elif method in ("PUT", "POST"): - internal_logger.warning( # pragma: no cover - "Content-Length or Transfer-Encoding header is required" - ) - self._type = ParseState.PARSE_NONE - real_payload.feed_eof() - self.done = True self.payload = real_payload diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index 32dd0e68b57..327d2b63d77 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -1230,8 +1230,8 @@ def test_parse_chunked_payload_chunk_extension(parser) -> None: assert payload.is_eof() -def _test_parse_no_length_or_te_on_post(loop, protocol, request_cls): - parser = request_cls(protocol, loop, readall=True) +def test_parse_no_length_or_te_on_post(loop: Any, protocol: Any, request_cls: Any): + parser = request_cls(protocol, loop, limit=2**16) text = b"POST /test HTTP/1.1\r\n\r\n" msg, payload = parser.feed_data(text)[0][0] @@ -1475,29 +1475,16 @@ def test_parse_bad_method_for_c_parser_raises(loop, protocol): class TestParsePayload: async def test_parse_eof_payload(self, stream) -> None: - out = aiohttp.FlowControlDataQueue( - stream, 2**16, loop=asyncio.get_event_loop() - ) - p = HttpPayloadParser(out, readall=True) + out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) + p = HttpPayloadParser(out) p.feed_data(b"data") p.feed_eof() assert out.is_eof() assert [(bytearray(b"data"), 4)] == list(out._buffer) - async def test_parse_no_body(self, stream) -> None: - out = aiohttp.FlowControlDataQueue( - stream, 2**16, loop=asyncio.get_event_loop() - ) - p = HttpPayloadParser(out, method="PUT") - - assert out.is_eof() - assert p.done - async def test_parse_length_payload_eof(self, stream) -> None: - out = aiohttp.FlowControlDataQueue( - stream, 2**16, loop=asyncio.get_event_loop() - ) + out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) p = HttpPayloadParser(out, length=4) p.feed_data(b"da") @@ -1622,10 +1609,8 @@ async def test_http_payload_parser_deflate_light(self, stream) -> None: assert out.is_eof() async def test_http_payload_parser_deflate_split(self, stream) -> None: - out = aiohttp.FlowControlDataQueue( - stream, 2**16, loop=asyncio.get_event_loop() - ) - p = HttpPayloadParser(out, compression="deflate", readall=True) + out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) + p = HttpPayloadParser(out, compression="deflate") # Feeding one correct byte should be enough to choose exact # deflate decompressor p.feed_data(b"x", 1) @@ -1634,10 +1619,8 @@ async def test_http_payload_parser_deflate_split(self, stream) -> None: assert b"data" == b"".join(d for d, _ in out._buffer) async def test_http_payload_parser_deflate_split_err(self, stream) -> None: - out = aiohttp.FlowControlDataQueue( - stream, 2**16, loop=asyncio.get_event_loop() - ) - p = HttpPayloadParser(out, compression="deflate", readall=True) + out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop()) + p = HttpPayloadParser(out, compression="deflate") # Feeding one wrong byte should be enough to choose exact # deflate decompressor p.feed_data(b"K", 1)