diff --git a/CHANGES/3070.bugfix b/CHANGES/3070.bugfix new file mode 100644 index 00000000000..185a7328c72 --- /dev/null +++ b/CHANGES/3070.bugfix @@ -0,0 +1,2 @@ +Many HTTP proxies has buggy keepalive support. +Let's not reuse connection but close it after processing every response. \ No newline at end of file diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index b42a769c704..00d98ebfff0 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -45,6 +45,9 @@ def should_close(self): self._payload_parser is not None or len(self) or self._tail) + def force_close(self): + self._should_close = True + def close(self): transport = self.transport if transport is not None: diff --git a/aiohttp/connector.py b/aiohttp/connector.py index ab4e8feb18a..24507c16027 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -895,6 +895,11 @@ async def _create_proxy_connection(self, req, traces, timeout): transport, proto = await self._create_direct_connection( proxy_req, [], timeout, client_error=ClientProxyConnectionError) + # Many HTTP proxies has buggy keepalive support. Let's not + # reuse connection but close it after processing every + # response. + proto.force_close() + auth = proxy_req.headers.pop(hdrs.AUTHORIZATION, None) if auth is not None: if not req.is_ssl():