fix: support both old and new websockets request headers format (#1588)
Co-authored-by: xujiayu <xujiayu@kaihong.com>
This commit is contained in:
@@ -641,7 +641,11 @@ class NonStreamingServer:
|
|||||||
path: str,
|
path: str,
|
||||||
request_headers: websockets.Headers,
|
request_headers: websockets.Headers,
|
||||||
) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]:
|
) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]:
|
||||||
if "sec-websocket-key" not in request_headers:
|
if "sec-websocket-key" not in (
|
||||||
|
request_headers.headers # For new request_headers
|
||||||
|
if hasattr(request_headers, "headers")
|
||||||
|
else request_headers # For old request_headers
|
||||||
|
):
|
||||||
# This is a normal HTTP request
|
# This is a normal HTTP request
|
||||||
if path == "/":
|
if path == "/":
|
||||||
path = "/index.html"
|
path = "/index.html"
|
||||||
|
|||||||
@@ -584,7 +584,11 @@ class StreamingServer(object):
|
|||||||
path: str,
|
path: str,
|
||||||
request_headers: websockets.Headers,
|
request_headers: websockets.Headers,
|
||||||
) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]:
|
) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]:
|
||||||
if "sec-websocket-key" not in request_headers:
|
if "sec-websocket-key" not in (
|
||||||
|
request_headers.headers # For new request_headers
|
||||||
|
if hasattr(request_headers, "headers")
|
||||||
|
else request_headers # For old request_headers
|
||||||
|
):
|
||||||
# This is a normal HTTP request
|
# This is a normal HTTP request
|
||||||
if path == "/":
|
if path == "/":
|
||||||
path = "/index.html"
|
path = "/index.html"
|
||||||
|
|||||||
Reference in New Issue
Block a user