Skip to content

Commit

Permalink
max_line_size, max_headers and max_field_size as params (aio-libs#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Prenner committed Jan 24, 2022
1 parent a1d4dac commit d882ed3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class ClientSession:
"_ws_response_class",
"_trace_configs",
"_read_bufsize",
"_max_line_size",
"_max_headers",
"_max_field_size",
)

def __init__(
Expand Down Expand Up @@ -218,6 +221,9 @@ def __init__(
requote_redirect_url: bool = True,
trace_configs: Optional[List[TraceConfig]] = None,
read_bufsize: int = 2 ** 16,
max_line_size: int = 8190,
max_headers: int = 32768,
max_field_size: int = 8190,
) -> None:
if base_url is None or isinstance(base_url, URL):
self._base_url: Optional[URL] = base_url
Expand Down Expand Up @@ -266,6 +272,9 @@ def __init__(
self._trust_env = trust_env
self._requote_redirect_url = requote_redirect_url
self._read_bufsize = read_bufsize
self._max_line_size = max_line_size
self._max_headers = max_headers
self._max_field_size = max_field_size

# Convert to list of tuples
if headers:
Expand Down Expand Up @@ -351,6 +360,9 @@ async def _request(
proxy_headers: Optional[LooseHeaders] = None,
trace_request_ctx: Optional[SimpleNamespace] = None,
read_bufsize: Optional[int] = None,
max_line_size: Optional[int] = 8190,
max_headers: Optional[int] = 32768,
max_field_size: Optional[int] = 8190,
) -> ClientResponse:

# NOTE: timeout clamps existing connect and read timeouts. We cannot
Expand Down Expand Up @@ -516,6 +528,9 @@ async def _request(
read_timeout=real_timeout.sock_read,
read_bufsize=read_bufsize,
timeout_ceil_threshold=self._connector._timeout_ceil_threshold,
max_line_size=max_line_size,
max_headers=max_headers,
max_field_size=max_field_size,
)

try:
Expand Down Expand Up @@ -1193,6 +1208,9 @@ def request(
version: HttpVersion = http.HttpVersion11,
connector: Optional[BaseConnector] = None,
read_bufsize: Optional[int] = None,
max_line_size: Optional[int] = 8190,
max_headers: Optional[int] = 32768,
max_field_size: Optional[int] = 8190,
) -> _SessionRequestContextManager:
"""Constructs and sends a request.
Expand Down Expand Up @@ -1263,6 +1281,9 @@ def request(
proxy=proxy,
proxy_auth=proxy_auth,
read_bufsize=read_bufsize,
max_line_size=max_line_size,
max_headers=max_headers,
max_field_size=max_field_size,
),
session,
)
6 changes: 6 additions & 0 deletions aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def set_response_params(
read_timeout: Optional[float] = None,
read_bufsize: int = 2 ** 16,
timeout_ceil_threshold: float = 5,
max_line_size: int = 8190,
max_headers: int = 32768,
max_field_size: int = 8190,
) -> None:
self._skip_payload = skip_payload

Expand All @@ -170,6 +173,9 @@ def set_response_params(
response_with_body=not skip_payload,
read_until_eof=read_until_eof,
auto_decompress=auto_decompress,
max_line_size=max_line_size,
max_headers=max_headers,
max_field_size=max_field_size,
)

if self._tail:
Expand Down

0 comments on commit d882ed3

Please sign in to comment.