101 Switching Protocols

The server is switching the connection to the protocol the client asked for in the Upgrade header.

Status

HTTP/1.1 101 Switching Protocols

Details

101 is the handshake that turns an ordinary HTTP connection into something else. The client sends Connection: Upgrade plus an Upgrade header naming the target protocol, and a server that agrees replies 101 with the same protocol name. Everything after the blank line following the 101 belongs to the new protocol, not to HTTP.

In practice this is how WebSocket connections start. The client sends Upgrade: websocket with a Sec-WebSocket-Key, the server answers 101 with the derived Sec-WebSocket-Accept, and the socket carries WebSocket frames from then on. HTTP/2 does not use this mechanism: its upgrade path was removed in favor of ALPN negotiation during the TLS handshake.

Note: HTTP/2 does not use this mechanism. Its upgrade path was removed in favour of ALPN negotiation during the TLS handshake.

Headers

Common causes

Usage notes

For clients

For servers

Examples

Opening a WebSocket connection

HTTP request

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

HTTP response

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

Notes for proxy users

Upgrades only survive a proxy that is explicitly WebSocket aware. HTTP proxies that terminate and re-issue requests will strip Connection and Upgrade as hop-by-hop headers, and the handshake fails with a plain 200 or 400. For proxied automation, tunnel WebSocket traffic with CONNECT rather than relying on header forwarding.

Specifications

See also