101 Switching Protocols

The HTTP 101 status code means a server is switching to a different protocol requested by a client.

Protocol upgrades

The protocol upgrade mechanism is commonly used to establish WebSocket connections. After the WebSocket connection is established, the server can use both HTTP and WebSocket protocols to communicate with a client (WebSocket protocol was designed to share the same ports with HTTP).

You can initiate protocol changes by sending the Upgrade and Connection headers:

GET /socket HTTP/1.1
Host: chat.example.com
Origin: https://example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: t5JpHMbiL1wzlkV1GBhzqw==
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Protocol: wamp
Sec-WebSocket-Version: 13

If the server supports and is willing to talk using a new protocol, it will send back the 101 Switching Protocols status code with the Upgrade header. If the server doesn’t want or can’t upgrade the connection, it will respond with the 200 OK status code.

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-Websocket-Accept: hz2kBDN0IrJPZHpoMoci6V9RzEE=
Sec-Websocket-Extensions: permessage-deflate

Once the WebSocket handshake completes successfully, the client and server can start the data transfer.

Note that you can’t upgrade HTTP/2 connections to different protocols because HTTP/2 doesn’t use connection-specific headers. That’s a design decision since in HTTP/2, the connection-specific metadata is conveyed by other means.


You might notice that 101 Web Socket Protocol Handshake and 101 Switching Protocols are used interchangeably. They both mean the same thing.

See also

426 Upgrade Required - when the server wants to force the client to upgrade a protocol.

Interested in no-nonsense technical guides?

No spyware, no promotional emails, or keyword-stuffed junk. I will only send you a single email when I've got something interesting to say. Unsubscribe anytime.

You can also subscribe to the Atom feed (it's like RSS, but better).