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

Commit 111b0b9

Browse files
committed
Re-add plaintext upgrade code.
1 parent d48ed85 commit 111b0b9

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

hyper/common/connection.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,9 @@ def get_response(self, *args, **kwargs):
137137
self._host, self._port, **self._h2_kwargs
138138
)
139139

140-
self._conn._sock = e.sock
140+
self._conn._connect_upgrade(e.sock)
141141
# stream id 1 is used by the upgrade request and response
142142
# and is half-closed by the client
143-
self._conn._new_stream(stream_id=1, local_closed=True)
144-
145-
# HTTP/2 preamble must be sent after receipt of a HTTP/1.1 101
146-
self._conn._send_preamble()
147143

148144
return self._conn.get_response(1)
149145

hyper/http20/connection.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,27 @@ def connect(self):
357357

358358
self._send_preamble()
359359

360+
def _connect_upgrade(self, sock):
361+
"""
362+
Called by the generic HTTP connection when we're being upgraded. Locks
363+
in a new socket and places the backing state machine into an upgrade
364+
state, then sends the preamble.
365+
"""
366+
self._sock = sock
367+
368+
with self._conn as conn:
369+
conn.initiate_upgrade_connection()
370+
conn.update_settings(
371+
{h2.settings.ENABLE_PUSH: int(self._enable_push)}
372+
)
373+
self._send_outstanding_data()
374+
375+
# The server will also send an initial settings frame, so get it.
376+
self._recv_cb()
377+
378+
s = self._new_stream(local_closed=True)
379+
self.recent_stream = s
380+
360381
def _send_preamble(self):
361382
"""
362383
Sends the necessary HTTP/2 preamble.

test/test_abstraction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ def __init__(self, host, port=None, secure=None, **kwargs):
110110
def _send_preamble(self):
111111
pass
112112

113+
def _connect_upgrade(self, sock):
114+
self._sock = sock
115+
113116
def _new_stream(self, *args, **kwargs):
114117
pass
115118

0 commit comments

Comments
 (0)