diff --git a/CHANGES/5012.bugfix b/CHANGES/5012.bugfix new file mode 100644 index 00000000000..8c429c231f6 --- /dev/null +++ b/CHANGES/5012.bugfix @@ -0,0 +1 @@ +Fix connection closing issue in HEAD request. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 6f8a8133d2b..21bf9249bca 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -140,6 +140,7 @@ Jakob Ackermann Jakub Wilk Jashandeep Sohi Jens Steinhauser +Jeonghun Lee Jeongkyu Shin Jeroen van der Heijden Jesus Cea diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index 5526bf26757..859398f4495 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -153,6 +153,7 @@ def set_response_params(self, *, timer: BaseTimerContext=None, self._parser = HttpResponseParser( self, self._loop, timer=timer, payload_exception=ClientPayloadError, + response_with_body=not skip_payload, read_until_eof=read_until_eof, auto_decompress=auto_decompress) diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index ecebea642d2..8fe0e2e1d4d 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -54,6 +54,37 @@ async def handler(request): assert 1 == len(client._session.connector._conns) +async def test_keepalive_after_head_requests_success( + aiohttp_client) -> None: + async def handler(request): + body = await request.read() + assert b'' == body + return web.Response(body=b'OK') + + cnt_conn_reuse = 0 + + async def on_reuseconn(session, ctx, params): + nonlocal cnt_conn_reuse + cnt_conn_reuse += 1 + + trace_config = aiohttp.TraceConfig() + trace_config._on_connection_reuseconn.append(on_reuseconn) + + app = web.Application() + app.router.add_route('GET', '/', handler) + + connector = aiohttp.TCPConnector(limit=1) + client = await aiohttp_client(app, connector=connector, + trace_configs=[trace_config]) + + resp1 = await client.head('/') + await resp1.read() + resp2 = await client.get('/') + await resp2.read() + + assert 1 == cnt_conn_reuse + + async def test_keepalive_response_released(aiohttp_client) -> None: async def handler(request): body = await request.read()