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 and HTTP/3 do not support the Upgrade mechanism.
- •The server must switch protocols immediately after sending the 101 response.
- •If the upgrade fails after 101 is sent, the connection must be closed.
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. The WebSocket handshake uses HTTP 101 to upgrade from HTTP to the WebSocket protocol. After the 101 response, communication switches to WebSocket frames.