diff --git a/aiohttp/client.py b/aiohttp/client.py index ffd90e88e79..d65e024a665 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -191,6 +191,9 @@ class ClientSession: "_ws_response_class", "_trace_configs", "_read_bufsize", + "_max_line_size", + "_max_headers", + "_max_field_size", ) def __init__( @@ -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 @@ -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: @@ -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 @@ -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: @@ -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. @@ -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, ) diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index 71942be52f4..68d18b9ffb3 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -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 @@ -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: