Switching Protocols
ActiveHTTP 101 Switching Protocols indicates the server is switching to a different protocol as requested by the client via the Upgrade header. Defined in RFC 9110 §15.2.2. Most commonly seen when upgrading an HTTP connection to WebSocket.
Description
The 101 Switching Protocols status code indicates that the server understands and is willing to comply with the client's request, via the Upgrade header field, for a change in the application protocol being used on this connection.
The server MUST generate an Upgrade header field in the response that indicates which protocol(s) will be in effect after this response. This is the mechanism used to establish WebSocket connections from an initial HTTP handshake.
Examples
GET /chat HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=Edge Cases
- •Only applies to HTTP/1.1. HTTP/2 (RFC 9113) and HTTP/3 do not support the Upgrade header mechanism. HTTP/2 uses the CONNECT method (RFC 9113 §8.5) for tunneling instead.
- •The server must switch protocols immediately after sending the 101 response.
- •If the upgrade fails after 101 is sent, the connection must be closed.
- •The Upgrade header in the response must explicitly name the protocol being switched to. Omitting it or naming a different protocol than what was requested is a protocol error.
When You'll See This
- →Establishing WebSocket connections
- →Upgrading HTTP/1.1 to HTTP/2 (h2c cleartext)
- →Legacy protocol transitions
Implementation References
| Language | Constant |
|---|---|
| Go | http.StatusSwitchingProtocols |
| Rust | http::StatusCode::SWITCHING_PROTOCOLS |
| Python | http.HTTPStatus.SWITCHING_PROTOCOLS |
| Node.js | http.STATUS_CODES[101] |
| .NET | HttpStatusCode.SwitchingProtocols |
| Java | HttpURLConnection.HTTP_SWITCHING_PROTOCOLS |
History
Introduced in HTTP/1.1 (RFC 2068, 1997). Became critical with the WebSocket protocol (RFC 6455, 2011) which uses this mechanism for the initial handshake.
Related Status Codes
Related Headers
FAQ
What does HTTP 101 Switching Protocols mean?
HTTP 101 means the server is changing to a different protocol (like WebSocket) as requested by the client via the Upgrade header.
Is HTTP 101 used for WebSocket?
Yes, for WebSocket over HTTP/1.1. The WebSocket handshake (RFC 6455) uses HTTP 101 to upgrade from HTTP to the WebSocket protocol. After the 101 response, communication switches to WebSocket frames. For WebSocket over HTTP/2 (RFC 8441), the mechanism is different: the client sends an extended CONNECT request with :protocol = websocket instead.
Does HTTP/2 support the 101 upgrade mechanism?
No. RFC 9113 §8.6 explicitly prohibits the Upgrade header field in HTTP/2. HTTP/2 uses the CONNECT method for tunneling instead. WebSocket over HTTP/2 (RFC 8441) uses an extended CONNECT with the :protocol pseudo-header, not a 101 response.