Performance: WebSocket authentication
MEDIUM IMPACT
This affects the initial connection setup time and ongoing message responsiveness in WebSocket communication.
async def websocket_endpoint(websocket: WebSocket, token: str): user = await authenticate_token(token) # Authenticate once during handshake if not user: await websocket.close() return await websocket.accept() while True: data = await websocket.receive_text() await websocket.send_text(f"Hello {user.name}")
async def websocket_endpoint(websocket: WebSocket): await websocket.accept() while True: data = await websocket.receive_text() user = await authenticate_token(data) # Authenticate on every message if not user: await websocket.close() break await websocket.send_text(f"Hello {user.name}")
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Authenticate on every message | N/A (WebSocket, no DOM) | N/A | N/A | [X] Bad |
| Authenticate once during handshake | N/A | N/A | N/A | [OK] Good |