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

Commit

Permalink
Implement HTTP20Adapter.close to close connections
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlei committed Feb 27, 2017
1 parent 28bfaba commit 94e25b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 94e25b9

Please sign in to comment.