fix: correctly call websocket_endpoint from _WSInterceptMiddleware
The middleware was calling the handler as a raw ASGI callable (scope, receive, send), but websocket_endpoint expects (WebSocket, token). This caused an AttributeError on every connection attempt, which made the frontend hit its 30s exponential backoff cap and spam reconnects. Fix: construct a WebSocket object from scope/receive/send and extract the ?token= query param before calling the handler, matching what FastAPI's routing machinery would do. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -88,7 +88,11 @@ class _WSInterceptMiddleware:
|
||||
|
||||
async def __call__(self, scope, receive, send) -> None:
|
||||
if scope["type"] == "websocket" and scope.get("path") == "/ws":
|
||||
await self._ws(scope, receive, send)
|
||||
from urllib.parse import parse_qs
|
||||
from starlette.websockets import WebSocket as _WS
|
||||
qs = parse_qs(scope.get("query_string", b"").decode())
|
||||
token = qs.get("token", [""])[0]
|
||||
await self._ws(_WS(scope, receive=receive, send=send), token)
|
||||
else:
|
||||
await self._app(scope, receive, send)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user