The server agrees to switch the connection to the protocol named in the Upgrade header, most often WebSocket.
101 Switching Protocols is the server accepting a client's Upgrade request on an HTTP/1.1 connection. After the empty line that ends the 101 response, the bytes on the connection belong to the new protocol. Almost every 101 you will see is a WebSocket handshake. HTTP/2 and HTTP/3 do not use 101; WebSockets over HTTP/2 use extended CONNECT (RFC 8441).
ws:// or wss:// connection.Upgrade: h2c), which is now rare.proxy_http_version 1.1;, proxy_set_header Upgrade $http_upgrade; and proxy_set_header Connection "upgrade";, otherwise the backend never sees the Upgrade and returns 200, 400 or 426.proxy_read_timeout (60 s by default in nginx) or send pings, or idle WebSockets will be cut.Sec-WebSocket-Accept header matches the key you sent; libraries do this for you.| Header | Role |
|---|---|
Upgrade | Names the new protocol, e.g. websocket. |
Connection | Must include Upgrade. |
Sec-WebSocket-Accept | WebSocket only: hash of the client's Sec-WebSocket-Key (RFC 6455). |
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=