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

Commit 7c00e5a

Browse files
committed
Cleaned up http11 upgrade to plaintext http20
1 parent 97e529e commit 7c00e5a

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

hyper/common/connection.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,23 @@ def get_response(self):
114114
return self._conn.get_response()
115115
except HTTPUpgrade as e:
116116
# We upgraded via the HTTP Upgrade mechanism. We can just
117-
#go straight to the world of HTTP/2. Replace the backing object
118-
#and insert the socket into it.
117+
# go straight to the world of HTTP/2. Replace the backing object
118+
# and insert the socket into it.
119119
assert e.negotiated == H2C_PROTOCOL
120120

121121
self._conn = HTTP20Connection(
122122
self._host, self._port, **self._h2_kwargs
123123
)
124124

125-
#stream id 1 is used by the upgrade request and response
126-
self.next_stream_id += 2
127125
self._conn._sock = e.sock
128-
126+
# stream id 1 is used by the upgrade request and response
127+
# and is half-closed by the client
128+
self._conn._new_stream(stream_id=1, local_closed=True)
129+
129130
# HTTP/2 preamble must be sent after receipt of a HTTP/1.1 101
130131
self._conn._send_preamble()
131-
132-
return e.resp
132+
133+
return self._conn.get_response(1)
133134

134135
# Can anyone say 'proxy object pattern'?
135136
def __getattr__(self, name):

hyper/common/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class HTTPUpgrade(Exception):
5656
"""
5757
We upgraded to a new protocol via the HTTP Upgrade response.
5858
"""
59-
def __init__(self, negotiated, sock, resp):
59+
def __init__(self, negotiated, sock):
6060
super(HTTPUpgrade, self).__init__()
6161
self.negotiated = negotiated
6262
self.sock = sock
63-
self.resp = resp

hyper/http11/connection.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from ..compat import bytes
2020

2121
from ..http20.connection import H2C_PROTOCOL
22-
from ..http20.response import HTTP20Response
2322
from ..packages.hyperframe.frame import SettingsFrame
2423

2524
# We prefer pycohttpparser to the pure-Python interpretation
@@ -181,9 +180,7 @@ def get_response(self):
181180

182181
if(response.status == 101 and
183182
b'upgrade' in headers['connection'] and bytes(H2C_PROTOCOL, 'utf-8') in headers['upgrade']):
184-
# HTTP/1.1 requests that are upgrade to HTTP/2.0 are responded to with steam id of 1
185-
headers[b':status'] = str(response.status)
186-
raise HTTPUpgrade(H2C_PROTOCOL, self._sock, HTTP20Response(headers, ))
183+
raise HTTPUpgrade(H2C_PROTOCOL, self._sock)
187184

188185
return HTTP11Response(
189186
response.status,

0 commit comments

Comments
 (0)