# 101 Switching Protocols

> https://http-status.org/docs/101

**Family:** 1xx Informational

## Rationale

Interim response: the server agrees to switch to a different protocol requested with Upgrade.

## In Plain Terms

The server is saying, 'Let's keep talking, but switch to a different protocol for the rest of this connection.'

## Description

The HTTP 101 Switching Protocols status code is an interim response that indicates the server understands and is willing to comply with the client's request to switch protocols on the current connection.

## Server Perspective

### Usage
- Return 101 for successful WebSocket upgrades
- Use it only when the protocol switch is explicitly requested and supported
- Use it only when the new protocol can still honor the semantics of the original request on this same connection
- WebSocket upgrade from HTTP
- Custom protocol upgrades on the same connection when both sides support them
- Real-time or bidirectional protocols negotiated through Upgrade

### Implementation
- Include Upgrade in the response and Connection: Upgrade so intermediaries treat the switch correctly
- After the 101 response, continue satisfying the original request using the new protocol instead of requiring the client to repeat it
- If the request also used Expect: 100-continue, send 100 before 101

### Common Headers
- Send Upgrade naming the protocol that will take effect and Connection: Upgrade to scope the header to this connection.

### Body
- Do not include a regular HTTP response body in the 101 response; the connection switches to the new protocol immediately after the headers.

### Pitfalls
- Do not use 101 unless the client actually requested an upgrade
- Do not use 101 as a redirect or as a way to move the client to a different connection, TCP socket, or TLS session
- Do not switch protocols if the new protocol cannot honor the original request semantics
- Do not use 101 to attempt an HTTP/2 upgrade via the Upgrade header; the h2c upgrade token is obsolete per RFC 9113 and HTTP/2 disallows this mechanism. Modern HTTP/2 connections are negotiated via ALPN at the TLS layer, not via 101.
- Normal HTTP requests that stay on the same protocol
- When the request did not ask for an upgrade
- When intermediaries or infrastructure do not support the switch
- As a generic redirect to HTTPS

## Client Perspective

### Pitfalls
- Do not expect a regular HTTP response body after a successful 101
- Do not treat 101 like a redirect that should open a second connection somewhere else

## Examples

### WebSocket handshake

The server accepts the WebSocket upgrade and the connection continues using the new protocol.

**Request:**
```
GET https://api.example.test/chat
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
```

**Response:**
```
101 Switching Protocols
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
```

## Related Codes

- [426 Upgrade Required](/docs/426.md)

