Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 94e25b9

Browse files
committed
Implement HTTP20Adapter.close to close connections
1 parent 28bfaba commit 94e25b9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

hyper/contrib.py

+4
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,7 @@ def getheaders(self, name):
157157
orig.msg = FakeOriginalResponse(resp.headers.iter_raw())
158158

159159
return response
160+
161+
def close(self):
162+
for connection in self.connections.values():
163+
connection._conn.close()

test/test_hyper.py

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import socket
2727
import zlib
2828
from io import BytesIO
29+
import requests
2930

3031
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
3132
TEST_CERTS_DIR = os.path.join(TEST_DIR, 'certs')
@@ -1128,6 +1129,22 @@ def test_adapter_accept_client_certificate(self):
11281129
cert=CLIENT_PEM_FILE)
11291130
assert conn1 is conn2
11301131

1132+
def test_adapter_close(self):
1133+
"""
1134+
Tests HTTP20Adapter properly closes connections
1135+
"""
1136+
s = requests.Session()
1137+
s.mount('https://', HTTP20Adapter())
1138+
s.close()
1139+
1140+
def test_adapter_close_context_manager(self):
1141+
"""
1142+
Tests HTTP20Adapter properly closes connections via context manager
1143+
"""
1144+
with requests.Session() as s:
1145+
a = HTTP20Adapter()
1146+
s.mount('https://', a)
1147+
11311148

11321149
class TestUtilities(object):
11331150
def test_combining_repeated_headers(self):

0 commit comments

Comments
 (0)