101 Switching Protocols HTTP Status Code

Description

HTTP status code 101, Switching Protocols, is sent in response to a client's request that includes an Upgrade header, indicating the client wishes to establish a connection using a different protocol than HTTP. This status code is part of the HTTP/1.1 specification.

When a server sends a response with status code 101, it agrees to switch protocols as requested by the client. After sending this response, the server will switch to the new protocol as specified in the request's Upgrade header. This is commonly used for opening a WebSocket connection, where the initial request is made over HTTP, and then the protocol is switched to WebSockets, allowing for full-duplex communication between the client and server.

The response to a request for protocol switching is not just limited to WebSockets; it can be used for any negotiated upgrade. However, it's important to note that both the client and server must support the new protocol for the switch to be successful.

Status

HTTP
101 Switching Protocols

Common Causes

Here are the primary causes or situations where a status code 101 might be used:

  1. Upgrading to WebSockets: One of the most common uses of the 101 status code is in the WebSocket handshake process. When a client wishes to start a WebSocket connection, it sends an HTTP request with an "Upgrade: websocket" header. If the server supports WebSockets and agrees to the protocol change, it responds with a status code 101, indicating that it will switch protocols from HTTP to WebSockets on that connection.

  2. Switching to a Newer HTTP Version: Although less common than the WebSocket upgrade, a client could request to switch to a newer version of the HTTP protocol (e.g., from HTTP/1.1 to HTTP/2) using the Upgrade header. If the server supports the requested protocol and agrees to switch, it will respond with a 101 status code before proceeding with the new protocol.

  3. Other Protocol Upgrades: The mechanism is not limited to WebSockets or HTTP versions; it can technically be used to upgrade to any other protocol that the server supports. The Upgrade header specifies the desired protocol(s), and the server can accept one of these with a 101 response.

The process generally involves the following steps:

  • The client sends an HTTP request indicating the desire to upgrade to a different protocol, typically including an "Upgrade" header specifying the target protocol(s) and a "Connection: upgrade" header to indicate that the Upgrade header field is significant.
  • If the server supports the requested protocol and wishes to switch, it responds with a 101 status code, indicating "Switching Protocols."
  • The server also includes an "Upgrade" header in the response to confirm the new protocol.
  • Following the 101 response, both the client and server switch to the new protocol over the same connection.

It's worth noting that the 101 status code is specifically for signaling protocol upgrades and is not used for error situations. The successful use of this code implies a mutual agreement between the client and server to change the communication protocol on the current connection.

Browser Support

The following table will show you the current browser support for the 101 Switching Protocols HTTP status code.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 30th March 2024