Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-103472: close response in HTTPConnection._tunnel #103473

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

Merged
merged 8 commits into from
May 2, 2023
Next Next commit
GH-103472: close response in HTTPConnection._tunnel
  • Loading branch information
graingert committed Apr 12, 2023
commit 86952ce000e32955b00532c2e3c5c8f66dd7f262
33 changes: 18 additions & 15 deletions 33 Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,23 +941,26 @@ def _tunnel(self):
del headers

response = self.response_class(self.sock, method=self._method)
(version, code, message) = response._read_status()
gpshead marked this conversation as resolved.
Show resolved Hide resolved
try:
(version, code, message) = response._read_status()

if code != http.HTTPStatus.OK:
self.close()
raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
while True:
line = response.fp.readline(_MAXLINE + 1)
if len(line) > _MAXLINE:
raise LineTooLong("header line")
if not line:
# for sites which EOF without sending a trailer
break
if line in (b'\r\n', b'\n', b''):
break
if code != http.HTTPStatus.OK:
self.close()
gpshead marked this conversation as resolved.
Show resolved Hide resolved
raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
while True:
line = response.fp.readline(_MAXLINE + 1)
if len(line) > _MAXLINE:
raise LineTooLong("header line")
if not line:
# for sites which EOF without sending a trailer
break
if line in (b'\r\n', b'\n', b''):
break

if self.debuglevel > 0:
print('header:', line.decode())
if self.debuglevel > 0:
print('header:', line.decode())
finally:
response.close()
gpshead marked this conversation as resolved.
Show resolved Hide resolved

def connect(self):
"""Connect to the host and port specified in __init__."""
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.