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

Commit 86c29f5

Browse filesBrowse files
committed
test that http.client _tunnel closes the response on exceptions
1 parent 5500734 commit 86c29f5
Copy full SHA for 86c29f5

File tree

1 file changed

+25
-4
lines changed
Filter options

1 file changed

+25
-4
lines changed

‎Lib/test/test_httplib.py

Copy file name to clipboardExpand all lines: Lib/test/test_httplib.py
+25-4Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,12 +2383,33 @@ def test_tunnel_debuglog(self):
23832383

23842384
self.conn.set_debuglevel(1)
23852385
self.conn._create_connection = self._create_connection(response_text)
2386+
self.conn.set_tunnel("destination.com")
2387+
self.conn.request('HEAD', '/', '')
2388+
2389+
2390+
def test_tunnel_leak(self):
2391+
sock = None
2392+
2393+
def _create_connection(address, timeout=None, source_address=None):
2394+
nonlocal sock
2395+
sock = FakeSocket(
2396+
'HTTP/1.1 404 NOT FOUND\r\n\r\n',
2397+
host=address[0],
2398+
port=address[1],
2399+
)
2400+
return sock
2401+
2402+
self.conn._create_connection = _create_connection
23862403
self.conn.set_tunnel('destination.com')
2404+
exc = None
2405+
try:
2406+
self.conn.request('HEAD', '/', '')
2407+
except OSError as e:
2408+
# keeping a reference to exc keeps response alive in the traceback
2409+
exc = e
2410+
self.assertIsNotNone(exc)
2411+
self.assertTrue(sock.file_closed)
23872412

2388-
with support.captured_stdout() as output:
2389-
self.conn.request('PUT', '/', '')
2390-
lines = output.getvalue().splitlines()
2391-
self.assertIn('header: {}'.format(expected_header), lines)
23922413

23932414

23942415
if __name__ == '__main__':

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.