Skip to content

Commit

Permalink
Exclude max_headers from new arguments (aio-libs#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan committed May 9, 2022
1 parent 188852b commit 80815a8
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 87 deletions.
2 changes: 1 addition & 1 deletion CHANGES/2304.feature
@@ -1 +1 @@
Support setting response header parameters max_line_size, max_headers and max_field_size.
Support setting response header parameters max_line_size and max_field_size.
10 changes: 0 additions & 10 deletions aiohttp/client.py
Expand Up @@ -192,7 +192,6 @@ class ClientSession:
"_trace_configs",
"_read_bufsize",
"_max_line_size",
"_max_headers",
"_max_field_size",
)

Expand Down Expand Up @@ -222,7 +221,6 @@ def __init__(
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):
Expand Down Expand Up @@ -273,7 +271,6 @@ def __init__(
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
Expand Down Expand Up @@ -361,7 +358,6 @@ async def _request(
trace_request_ctx: Optional[SimpleNamespace] = None,
read_bufsize: Optional[int] = None,
max_line_size: Optional[int] = None,
max_headers: Optional[int] = None,
max_field_size: Optional[int] = None,
) -> ClientResponse:

Expand Down Expand Up @@ -426,9 +422,6 @@ async def _request(
if max_line_size is None:
max_line_size = self._max_line_size

if max_headers is None:
max_headers = self._max_headers

if max_field_size is None:
max_field_size = self._max_field_size

Expand Down Expand Up @@ -538,7 +531,6 @@ async def _request(
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,
)

Expand Down Expand Up @@ -1218,7 +1210,6 @@ def request(
connector: Optional[BaseConnector] = None,
read_bufsize: Optional[int] = None,
max_line_size: int = 8190,
max_headers: int = 32768,
max_field_size: int = 8190,
) -> _SessionRequestContextManager:
"""Constructs and sends a request.
Expand Down Expand Up @@ -1291,7 +1282,6 @@ def request(
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,
Expand Down
2 changes: 0 additions & 2 deletions aiohttp/client_proto.py
Expand Up @@ -154,7 +154,6 @@ def set_response_params(
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 @@ -174,7 +173,6 @@ def set_response_params(
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,
)

Expand Down
6 changes: 0 additions & 6 deletions docs/client_reference.rst
Expand Up @@ -54,7 +54,6 @@ The client session supports the context manager protocol for self closing.
trust_env=False, \
trace_configs=None, \
max_line_size=8190, \
max_headers=32768, \
max_field_size=8190)

The class for creating client sessions and making requests.
Expand Down Expand Up @@ -206,8 +205,6 @@ The client session supports the context manager protocol for self closing.

:param max_line_size: The maximum length allowed for the HTTP response reason field.

:param max_headers: The maximum number of response headers allowed.

:param max_field_size: The maximum length allowed for response header values.

.. attribute:: closed
Expand Down Expand Up @@ -349,7 +346,6 @@ The client session supports the context manager protocol for self closing.
verify_ssl=None, fingerprint=None, \
ssl_context=None, proxy_headers=None, \
max_line_size=8190, \
max_headers=32768, \
max_field_size=8190)
:async-with:
:coroutine:
Expand Down Expand Up @@ -524,8 +520,6 @@ The client session supports the context manager protocol for self closing.

:param max_line_size: The maximum length allowed for the HTTP response reason field.

:param max_headers: The maximum number of response headers allowed.

:param max_field_size: The maximum length allowed for response header values.

:return ClientResponse: a :class:`client response <ClientResponse>`
Expand Down
68 changes: 0 additions & 68 deletions tests/test_client_functional.py
Expand Up @@ -3130,71 +3130,3 @@ async def handler(request):

async with await client.get("/", max_line_size=8191) as resp:
assert resp.reason == "x" * 8191


async def test_max_headers_session_default(aiohttp_client: Any) -> None:
async def handler(request):
# generate 32764 headers:
# 32768 (max_headers default) minus 4 headers which are set implicitly
# 'Content-Length', 'Content-Type', 'Date' and 'Server'
headers = MultiDict()
for x in range(32764):
headers.add(f"x-header-{x}", str(x))
return web.Response(headers=headers)

app = web.Application()
app.add_routes([web.get("/", handler)])

client = await aiohttp_client(app)

async with await client.get("/") as resp:
assert len(resp.headers) == 32768


@pytest.mark.xfail
async def test_max_headers_session_default_fail(aiohttp_client: Any) -> None:
async def handler(request):
headers = MultiDict()
for x in range(32769):
headers.add(f"x-header-{x}", str(x))
return web.Response(headers=headers)

app = web.Application()
app.add_routes([web.get("/", handler)])

client = await aiohttp_client(app)

with pytest.raises(aiohttp.ClientResponseError):
await client.get("/")


async def test_max_headers_session_explicit(aiohttp_client: Any) -> None:
async def handler(request):
headers = MultiDict()
for x in range(32765):
headers.add(f"x-header-{x}", str(x))
return web.Response(headers=headers)

app = web.Application()
app.add_routes([web.get("/", handler)])

client = await aiohttp_client(app, max_headers=32769)

async with await client.get("/") as resp:
assert len(resp.headers) == 32769


async def test_max_headers_request_explicit(aiohttp_client: Any) -> None:
async def handler(request):
headers = MultiDict()
for x in range(32765):
headers.add(f"x-header-{x}", str(x))
return web.Response(headers=headers)

app = web.Application()
app.add_routes([web.get("/", handler)])

client = await aiohttp_client(app)

async with await client.get("/", max_headers=32769) as resp:
assert len(resp.headers) == 32769

0 comments on commit 80815a8

Please sign in to comment.