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

Implement HTTP20Adapter.close to close connections #307

Open
wants to merge 1 commit into
base: development
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
4 changes: 4 additions & 0 deletions hyper/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
17 changes: 17 additions & 0 deletions test/test_hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down