JiayuXu
Committed by GitHub

fix: support both old and new websockets request headers format (#1588)

Co-authored-by: xujiayu <xujiayu@kaihong.com>
@@ -641,7 +641,11 @@ class NonStreamingServer: @@ -641,7 +641,11 @@ class NonStreamingServer:
641 path: str, 641 path: str,
642 request_headers: websockets.Headers, 642 request_headers: websockets.Headers,
643 ) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]: 643 ) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]:
644 - if "sec-websocket-key" not in request_headers: 644 + if "sec-websocket-key" not in (
  645 + request_headers.headers # For new request_headers
  646 + if hasattr(request_headers, "headers")
  647 + else request_headers # For old request_headers
  648 + ):
645 # This is a normal HTTP request 649 # This is a normal HTTP request
646 if path == "/": 650 if path == "/":
647 path = "/index.html" 651 path = "/index.html"
@@ -584,7 +584,11 @@ class StreamingServer(object): @@ -584,7 +584,11 @@ class StreamingServer(object):
584 path: str, 584 path: str,
585 request_headers: websockets.Headers, 585 request_headers: websockets.Headers,
586 ) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]: 586 ) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]:
587 - if "sec-websocket-key" not in request_headers: 587 + if "sec-websocket-key" not in (
  588 + request_headers.headers # For new request_headers
  589 + if hasattr(request_headers, "headers")
  590 + else request_headers # For old request_headers
  591 + ):
588 # This is a normal HTTP request 592 # This is a normal HTTP request
589 if path == "/": 593 if path == "/":
590 path = "/index.html" 594 path = "/index.html"