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

Commit 3ebdf58

Browse files
committed
Make HTTP20Adapter reuse connections.
1 parent d586530 commit 3ebdf58

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

hyper/contrib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def get_connection(self, netloc):
3535
conn = self.connections[netloc]
3636
except KeyError:
3737
conn = HTTP20Connection(netloc)
38+
self.connections[netloc] = conn
3839

3940
return conn
4041

test/test_hyper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Stream, STATE_HALF_CLOSED_LOCAL, STATE_OPEN, MAX_CHUNK, STATE_CLOSED
1313
)
1414
from hyper.http20.response import HTTP20Response
15+
from hyper.contrib import HTTP20Adapter
1516
import pytest
1617
import zlib
1718
from io import BytesIO
@@ -1081,6 +1082,15 @@ def test_response_transparently_decrypts_wrong_deflate(self):
10811082
assert resp.read() == b'this is test data'
10821083

10831084

1085+
class TestHTTP20Adapter(object):
1086+
def test_adapter_reuses_connections(self):
1087+
a = HTTP20Adapter()
1088+
conn1 = a.get_connection('twitter.com')
1089+
conn2 = a.get_connection('twitter.com')
1090+
1091+
assert conn1 is conn2
1092+
1093+
10841094
# Some utility classes for the tests.
10851095
class NullEncoder(object):
10861096
def encode(headers):

0 commit comments

Comments
 (0)