What HTTP 101 means
Every WebSocket connection starts as an HTTP/1.1 request with Upgrade: websocket and Connection: Upgrade. A 101 response completes the handshake, and from then on the TCP connection speaks the WebSocket protocol instead of HTTP.
Using 101 correctly
-
Behind nginx, WebSocket upgrades only work if you forward the headers:
proxy_set_header Upgrade $http_upgrade;andproxy_set_header Connection "upgrade";. - HTTP/2 and HTTP/3 don’t use 101. WebSockets over them use extended CONNECT instead.
Retrying
Not applicable: this isn’t an error.
Example response
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Related status codes
- 426 Upgrade Required : The server refuses the request over the current protocol, and the client must upgrade.
- 400 Bad Request : The server can’t process the request because it is malformed.
- 100 Continue : Tells the client to go ahead and send the request body.
Other 1xx status codes
100 Continue · 103 Early Hints
See the full list of HTTP status codes.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What does HTTP 101 Switching Protocols mean?
HTTP 101 Switching Protocols means the server agrees to switch to the protocol the client asked for, such as WebSocket. Every WebSocket connection starts as an HTTP/1.1 request with Upgrade: websocket and Connection: Upgrade. A 101 response completes the handshake, and from then on the TCP connection speaks the WebSocket protocol instead of HTTP.