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 11, 2017
1 parent 28bfaba commit ed08296
Show file tree
Hide file tree
Showing 2 changed files with 24 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()
20 changes: 20 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,25 @@ def test_adapter_accept_client_certificate(self):
cert=CLIENT_PEM_FILE)
assert conn1 is conn2

def test_adapter_close(self):
"""
This tests HTTP20Adapter properly closes connections
"""
s = requests.Session()
a = HTTP20Adapter()
s.mount('https://http2bin.org', a)
s.get('https://http2bin.org/')
s.close()

def test_adapter_close_context_manager(self):
"""
This tests HTTP20Adapter properly closes connections via context manager
"""
with requests.Session() as s:
a = HTTP20Adapter()
s.mount('https://http2bin.org', a)
s.get('https://http2bin.org/')


class TestUtilities(object):
def test_combining_repeated_headers(self):
Expand Down

0 comments on commit ed08296

Please sign in to comment.