Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in creating proxy connection of TCPConnector. #6703

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/6239.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug in creating a proxy connection.
8 changes: 8 additions & 0 deletions aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ class ClientHttpProxyError(ClientResponseError):
"""


class ClientProxyClosedError(ClientResponseError):
"""Proxy server is closed.

Raised in :class:`aiohttp.connector.TCPConnector` if
proxy server is closed on ``CONNECT`` request.
"""


class TooManyRedirects(ClientResponseError):
"""Client was redirected too many times."""

Expand Down
9 changes: 9 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
ClientConnectorError,
ClientConnectorSSLError,
ClientHttpProxyError,
ClientProxyClosedError,
ClientProxyConnectionError,
ServerFingerprintMismatch,
UnixClientConnectorError,
Expand Down Expand Up @@ -1229,6 +1230,14 @@ async def _create_proxy_connection(
message=message,
headers=resp.headers,
)
elif resp.method == hdrs.METH_CONNECT and resp.closed:
raise ClientProxyClosedError(
proxy_resp.request_info,
resp.history,
status=resp.status,
message="Proxy server is closed.",
headers=resp.headers,
)
except BaseException:
# It shouldn't be closed in `finally` because it's fed to
# `loop.start_tls()` and the docs say not to touch it after
Expand Down