Informational
101

Switching Protocols

The server agrees to switch protocols as requested by the client via an Upgrade header.

# Quick Definition

The 101 Switching Protocols status code indicates that the server understands and is willing to comply with the client's request to change the application protocol being used on this connection. The server will switch to the protocol defined in the response's Upgrade header immediately after the empty line that terminates the 101 response.

# When Does a 101 Response Occur?

A 101 response is returned when the client sends a request with an Upgrade header asking the server to switch to a different protocol, and the server agrees. The most common scenario is a WebSocket handshake, where the client requests an upgrade from HTTP/1.1 to the WebSocket protocol.

The client initiates the switch by including Connection: Upgrade and Upgrade: websocket headers (along with a security key). If the server supports WebSocket and accepts the request, it responds with 101 and the connection transitions from HTTP to a full-duplex WebSocket channel.

# Common Use Cases

# Best Practices

  1. Always validate the Sec-WebSocket-Key -- The server must compute the correct Sec-WebSocket-Accept value by concatenating the key with the magic GUID and returning the Base64-encoded SHA-1 hash.
  2. Configure reverse proxies correctly -- Nginx requires proxy_set_header Upgrade $http_upgrade and proxy_set_header Connection "upgrade" to forward WebSocket upgrades.
  3. Implement heartbeat/ping frames -- Use WebSocket ping/pong frames to detect dead connections and prevent intermediaries from closing idle connections.
  4. Handle upgrade failures gracefully -- If the server cannot upgrade, fall back to HTTP long-polling or Server-Sent Events for real-time functionality.
  5. Use wss:// in production -- Always use secure WebSocket connections (WSS) over TLS to prevent intermediary interference and ensure data privacy.

# HTTP Example

Request
GET /chat HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
Response
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

# Related Status Codes

# Frequently Asked Questions

Is 101 only used for WebSocket upgrades? +
No, 101 Switching Protocols can be used for any protocol upgrade, not just WebSocket. However, in practice, the WebSocket upgrade is by far the most common use case. Historically it was also used for upgrading from HTTP/1.0 to HTTP/1.1 and for TLS upgrades, though those patterns are rarely seen today.
What happens if the server doesn't support the requested protocol? +
If the server doesn't support or refuses the protocol switch, it will not return a 101. Instead, it will continue processing the request using the original protocol and return a standard HTTP response, typically a 200 OK or a 400 Bad Request if the upgrade request was malformed.
Does HTTP/2 use 101 Switching Protocols? +
No, HTTP/2 does not use 101 Switching Protocols. HTTP/2 negotiation happens during the TLS handshake via ALPN (Application-Layer Protocol Negotiation), which occurs before any HTTP messages are exchanged. The 101 status code is specific to HTTP/1.1 protocol upgrades.

Monitor your WebSocket connections

Track uptime, latency, and connection health for your real-time services around the clock.

Start Free Monitoring