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.
In more detail
It is how every WebSocket begins. The handshake is still an HTTP request, so it is the natural place to authenticate the caller and agree a subprotocol before messages flow.
Example
In Node.js the server emits upgrade with the request and the raw socket; after that you own the socket and must destroy it on shutdown.Related terms
- WebSocket — A protocol that turns an HTTP connection into a long-lived, two-way channel where client and server can each send messages at any time.
- subprotocol — The application-level message format agreed on top of a WebSocket during the handshake, named in the Sec-WebSocket-Protocol header.
- HTTP — The protocol web browsers and web servers use to send requests and responses.
- 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.
Taught in
- WebSockets — Modern API Architecture: REST, GraphQL & gRPC
- Bidirectional WebSockets: Reconnection & Heartbeats — Production Full-Stack Engineering
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services