topic
Verified 2026-09-18WebSocket Upgrade
WebSocket starts with an HTTP handshake and then upgrades the connection to a bidirectional protocol.
Validate the Origin and negotiate the requested subprotocol and extensions. A successful handshake returns 101 Switching Protocols.
httpwebsocketupgraderealtime
Reference (http)
GET /chat HTTP/1.1 Upgrade: websocket Connection: Upgrade Sec-WebSocket-Version: 13 Sec-WebSocket-Key: <nonce>
Validate the Origin and negotiate the requested subprotocol and extensions. A successful handshake returns 101 Switching Protocols.
Common mistakes
- Accepting every Origin or treating the WebSocket handshake as proof of user authentication.
Sources