Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused readall from Python parser #8096

Merged
merged 13 commits into from
Apr 21, 2024
20 changes: 1 addition & 19 deletions aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -242,7 +241,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,
Expand All @@ -255,7 +253,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
Expand Down Expand Up @@ -381,7 +378,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,
Expand All @@ -401,7 +397,6 @@ def get_content_length() -> Optional[int]:
payload,
method=msg.method,
compression=msg.compression,
readall=True,
auto_decompress=self._auto_decompress,
lax=self.lax,
)
Expand All @@ -419,7 +414,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,
Expand Down Expand Up @@ -739,13 +733,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""
Expand All @@ -767,7 +760,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:
Expand All @@ -776,16 +768,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

Expand Down
17 changes: 5 additions & 12 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,8 @@ def test_parse_chunked_payload_chunk_extension(parser: Any) -> 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]

Expand Down Expand Up @@ -1488,20 +1488,13 @@ def test_parse_bad_method_for_c_parser_raises(loop: Any, protocol: Any) -> None:
class TestParsePayload:
async def test_parse_eof_payload(self, stream: Any) -> None:
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())
p = HttpPayloadParser(out, readall=True)
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: Any) -> 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: Any) -> None:
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())

Expand Down Expand Up @@ -1627,7 +1620,7 @@ async def test_http_payload_parser_deflate_light(self, stream: Any) -> None:

async def test_http_payload_parser_deflate_split(self, stream: Any) -> None:
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())
p = HttpPayloadParser(out, compression="deflate", readall=True)
p = HttpPayloadParser(out, compression="deflate")
# Feeding one correct byte should be enough to choose exact
# deflate decompressor
p.feed_data(b"x", 1)
Expand All @@ -1637,7 +1630,7 @@ async def test_http_payload_parser_deflate_split(self, stream: Any) -> None:

async def test_http_payload_parser_deflate_split_err(self, stream: Any) -> None:
out = aiohttp.FlowControlDataQueue(stream, 2**16, loop=asyncio.get_event_loop())
p = HttpPayloadParser(out, compression="deflate", readall=True)
p = HttpPayloadParser(out, compression="deflate")
# Feeding one wrong byte should be enough to choose exact
# deflate decompressor
p.feed_data(b"K", 1)
Expand Down
Loading