diff --git a/hyper/contrib.py b/hyper/contrib.py index dccec518..958addb9 100644 --- a/hyper/contrib.py +++ b/hyper/contrib.py @@ -157,3 +157,7 @@ def getheaders(self, name): orig.msg = FakeOriginalResponse(resp.headers.iter_raw()) return response + + def close(self): + for connection in self.connections.values(): + connection._conn.close() diff --git a/test/test_hyper.py b/test/test_hyper.py index 6a18d592..b5413118 100644 --- a/test/test_hyper.py +++ b/test/test_hyper.py @@ -26,6 +26,7 @@ import socket import zlib from io import BytesIO +import requests TEST_DIR = os.path.abspath(os.path.dirname(__file__)) TEST_CERTS_DIR = os.path.join(TEST_DIR, 'certs') @@ -1128,6 +1129,22 @@ def test_adapter_accept_client_certificate(self): cert=CLIENT_PEM_FILE) assert conn1 is conn2 + def test_adapter_close(self): + """ + Tests HTTP20Adapter properly closes connections + """ + s = requests.Session() + s.mount('https://', HTTP20Adapter()) + s.close() + + def test_adapter_close_context_manager(self): + """ + Tests HTTP20Adapter properly closes connections via context manager + """ + with requests.Session() as s: + a = HTTP20Adapter() + s.mount('https://', a) + class TestUtilities(object): def test_combining_repeated_headers(self):