101 Switching Protocols
The server agrees to switch to the different protocol the client asked for in its Upgrade header, such as WebSocket.
What 101 Switching Protocols means
A client sends Upgrade and Connection: Upgrade headers to ask for a new protocol on the same connection. If the server agrees, it replies 101 with an Upgrade header naming the protocol, and from then on both sides speak that protocol.
The WebSocket handshake is the most common example: a GET with Upgrade: websocket gets 101 back. HTTP/2 and HTTP/3 do not use 101; WebSockets over HTTP/2 use the extended CONNECT method instead.
Headers that go with it
UpgradeConnection
Example response
HTTP/1.1 101 Switching Protocols
Upgrade: HTTP/2.0How to check for a 101 response
cURL
# Print only the status code
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/JavaScript (Node.js)
const res = await fetch("https://example.com/");
if (res.status === 101) {
console.log(res.status, res.statusText);
}Python
import requests
res = requests.get("https://example.com/")
if res.status_code == 101:
print(res.status_code, res.reason)Go
res, err := http.Get("https://example.com/")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 101 {
fmt.Println(res.Status)
}Specification
101 Switching Protocols is defined in RFC 9110, section 15.2.2.
Related status codes
- 426
The server refuses to handle the request over the current protocol, and its Upgrade header names the protocol to switch to.
- 100
The server got the request headers and has not rejected them, so the client should go ahead and send the request body.
- 200
The request worked. The response body holds the result, such as the page, file or JSON data the client asked for.