@@ -214,6 +214,7 @@ def parse(
214
214
read_exact : Callable [[int ], Generator [None , None , bytes ]],
215
215
read_to_eof : Callable [[int ], Generator [None , None , bytes ]],
216
216
include_body : bool = True ,
217
+ allow_http10 : bool = False ,
217
218
) -> Generator [None , None , Response ]:
218
219
"""
219
220
Parse a WebSocket handshake response.
@@ -249,10 +250,17 @@ def parse(
249
250
protocol , raw_status_code , raw_reason = status_line .split (b" " , 2 )
250
251
except ValueError : # not enough values to unpack (expected 3, got 1-2)
251
252
raise ValueError (f"invalid HTTP status line: { d (status_line )} " ) from None
252
- if protocol != b"HTTP/1.1" :
253
- raise ValueError (
254
- f"unsupported protocol; expected HTTP/1.1: { d (status_line )} "
255
- )
253
+ if allow_http10 : # some proxies still use HTTP/1.0
254
+ if protocol not in [b"HTTP/1.1" , b"HTTP/1.0" ]:
255
+ raise ValueError (
256
+ f"unsupported protocol; expected HTTP/1.1 or HTTP/1.0: "
257
+ f"{ d (status_line )} "
258
+ )
259
+ else :
260
+ if protocol != b"HTTP/1.1" :
261
+ raise ValueError (
262
+ f"unsupported protocol; expected HTTP/1.1: { d (status_line )} "
263
+ )
256
264
try :
257
265
status_code = int (raw_status_code )
258
266
except ValueError : # invalid literal for int() with base 10
0 commit comments