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

Commit 06535a1

Browse files
committed
Spike for HTTP20Adapter to use HTTP/1.1
1 parent f605772 commit 06535a1

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

hyper/contrib.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except ImportError: # pragma: no cover
1515
HTTPAdapter = object
1616

17-
from hyper import HTTP20Connection
17+
from hyper.common.connection import HTTPConnection
1818
from hyper.compat import urlparse
1919

2020
class HTTP20Adapter(HTTPAdapter):
@@ -27,15 +27,21 @@ def __init__(self, *args, **kwargs):
2727
#: A mapping between HTTP netlocs and ``HTTP20Connection`` objects.
2828
self.connections = {}
2929

30-
def get_connection(self, netloc):
30+
def get_connection(self, host, port, scheme):
3131
"""
32-
Gets an appropriate HTTP/2 connection object based on netloc.
32+
Gets an appropriate HTTP/2 connection object based on host/port/scheme
33+
tuples.
3334
"""
35+
secure = scheme == 'https'
36+
37+
if port is None:
38+
port = 80 if not secure else 443
39+
3440
try:
35-
conn = self.connections[netloc]
41+
conn = self.connections[(host, port, scheme)]
3642
except KeyError:
37-
conn = HTTP20Connection(netloc)
38-
self.connections[netloc] = conn
43+
conn = HTTPConnection(host, port, secure=secure)
44+
self.connections[(host, port, scheme)] = conn
3945

4046
return conn
4147

@@ -45,20 +51,20 @@ def send(self, request, stream=False, **kwargs):
4551
"""
4652
parsed = urlparse(request.url)
4753

48-
conn = self.get_connection(parsed.netloc)
54+
conn = self.get_connection(parsed.hostname, parsed.port, parsed.scheme)
4955

5056
# Build the selector.
5157
selector = parsed.path
5258
selector += '?' + parsed.query if parsed.query else ''
5359
selector += '#' + parsed.fragment if parsed.fragment else ''
5460

55-
stream_id = conn.request(
61+
conn.request(
5662
request.method,
5763
selector,
5864
request.body,
5965
request.headers
6066
)
61-
resp = conn.get_response(stream_id)
67+
resp = conn.get_response()
6268

6369
r = self.build_response(request, resp)
6470

test/test_hyper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,8 +2076,8 @@ def test_read_compressed_frames(self):
20762076
class TestHTTP20Adapter(object):
20772077
def test_adapter_reuses_connections(self):
20782078
a = HTTP20Adapter()
2079-
conn1 = a.get_connection('http2bin.org')
2080-
conn2 = a.get_connection('http2bin.org')
2079+
conn1 = a.get_connection('http2bin.org', 80, 'http')
2080+
conn2 = a.get_connection('http2bin.org', 80, 'http')
20812081

20822082
assert conn1 is conn2
20832083

0 commit comments

Comments
 (0)