Skip to content

Commit

Permalink
fix: support both old and new websockets request headers format (#1588)
Browse files Browse the repository at this point in the history
Co-authored-by: xujiayu <[email protected]>
  • Loading branch information
JiayuXu0 and xujiayu authored Dec 3, 2024
1 parent dc3287f commit 0d6bf52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion python-api-examples/non_streaming_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,11 @@ async def process_request(
path: str,
request_headers: websockets.Headers,
) -> 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
if path == "/":
path = "/index.html"
Expand Down
6 changes: 5 additions & 1 deletion python-api-examples/streaming_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@ async def process_request(
path: str,
request_headers: websockets.Headers,
) -> 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
if path == "/":
path = "/index.html"
Expand Down

0 comments on commit 0d6bf52

Please sign in to comment.