Skip to content

101 Switching Protocol (HTTP Status Code 101 )

Updated: at 09:12 AM

HTTP status code 101 “Switching Protocols” is an informational status code indicating that the server has understood the client’s request and will notify the client through the Upgrade header to adopt a different protocol to fulfill this request. After sending this response followed by a blank line, the server will switch to the protocols defined in the Upgrade header.

This status code is commonly used during the WebSocket protocol upgrade process. WebSocket is a protocol for full-duplex communication over a single TCP connection, allowing the server to push data to the client without the client needing to send a request. When a client sends an HTTP request and wishes to upgrade the connection to a WebSocket connection, if the server agrees to switch protocols, it will return a 101 status code and include the Upgrade and Connection headers in the response, indicating the switch to WebSocket.

For example, the client might send the following request:

GET /chat HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Version: 13

If the server agrees to upgrade, it might return the following response:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

In this example, the server agrees to upgrade to the WebSocket protocol and returns the corresponding response headers. After receiving the response, the client can upgrade the connection to a WebSocket connection and begin full-duplex communication.