@@ -132,15 +132,9 @@ def request(self, method, url, body=None, headers={}):
132
132
133
133
if self ._sock is None :
134
134
self .connect ()
135
-
136
- #add HTTP Upgrade headers
137
- headers [b'connection' ] = b'Upgrade, HTTP2-Settings'
138
- headers [b'upgrade' ] = H2C_PROTOCOL
139
135
140
- #need to encode SETTINGS frame payload in Base64 and put into the HTTP-2 Settings header
141
- http2_settings = SettingsFrame (0 )
142
- http2_settings .settings [SettingsFrame .INITIAL_WINDOW_SIZE ] = 65535
143
- headers [b'HTTP2-Settings' ] = base64 .b64encode (http2_settings .serialize_body ())
136
+ # TODO: Only send upgrade headers on first request
137
+ self ._add_upgrade_headers (headers )
144
138
145
139
# We may need extra headers.
146
140
if body :
@@ -178,8 +172,8 @@ def get_response(self):
178
172
179
173
self ._sock .advance_buffer (response .consumed )
180
174
181
- if (response .status == 101 and
182
- b'upgrade' in headers ['connection' ] and bytes ( H2C_PROTOCOL , 'utf-8' ) in headers ['upgrade' ]):
175
+ if (response .status == 101 and
176
+ b'upgrade' in headers ['connection' ] and H2C_PROTOCOL . decode ( 'utf-8' ) in headers ['upgrade' ]):
183
177
raise HTTPUpgrade (H2C_PROTOCOL , self ._sock )
184
178
185
179
return HTTP11Response (
@@ -233,6 +227,16 @@ def _add_body_headers(self, headers, body):
233
227
headers [b'transfer-encoding' ] = b'chunked'
234
228
return BODY_CHUNKED
235
229
230
+ def _add_upgrade_headers (self , headers ):
231
+ # Add HTTP Upgrade headers.
232
+ headers [b'connection' ] = b'Upgrade, HTTP2-Settings'
233
+ headers [b'upgrade' ] = H2C_PROTOCOL
234
+
235
+ # Encode SETTINGS frame payload in Base64 and put into the HTTP-2 Settings header.
236
+ http2_settings = SettingsFrame (0 )
237
+ http2_settings .settings [SettingsFrame .INITIAL_WINDOW_SIZE ] = 65535
238
+ headers [b'HTTP2-Settings' ] = base64 .b64encode (http2_settings .serialize_body ())
239
+
236
240
def _send_body (self , body , body_type ):
237
241
"""
238
242
Handles the HTTP/1.1 logic for sending HTTP bodies. This does magical
0 commit comments