WebSockets
Cheat sheet · https://pcornel.dk/topic.php?topic=6266
Answer
WebSocket (RFC 6455) turns an HTTP connection into a long-lived, full-duplex message channel. It starts as an HTTP/1.1 request with Upgrade: websocket and the server answers 101 Switching Protocols.
Remember
Every proxy on the path must pass the Upgrade and Connection headers and allow long idle times. nginx needs proxy_http_version 1.1 and explicit Upgrade/Connection headers; its default 60 s read timeout closes idle sockets. Check Origin on the server to prevent cross-site WebSocket hijacking.
First checks
- Browser developer tools → Network → WS: status 101, frames, close code.
curl -i -N --http1.1 -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" https://<host>/ws— expect HTTP/1.1 101.- Proxy config: Upgrade/Connection headers and read/tunnel timeout.
Verify in this order
HTTP/1.1 GET with Upgrade → every proxy forwards Upgrade/Connection → backend 101 Switching Protocols → framed messages both ways → ping/pong keepalive → close handshake
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6266