Sec-WebSocket-Key and Sec-WebSocket-Accept
The WebSocket handshake headers: the client sends a random key, and the server proves it understood by returning a SHA-1 hash of that key joined to a fixed magic string.
In more detail
The result is sent as Base64. It stops ordinary HTTP servers or caches from being mistaken for WebSocket servers, but it is not an authentication mechanism.
Related terms
- HTTP upgrade — The exchange in which a client asks, with an Upgrade header, to switch an HTTP connection to another protocol, and the server agrees with 101 Switching Protocols.
- SHA-1 — An older hash function producing a 160-bit value, now considered broken for security because collisions can be created on purpose.
- magic number — A fixed value, placed at the start of a file or message or built into a protocol, that lets a reader recognise the format.
Taught in
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services