Switching Protocols
The server understands and is willing to comply with the client's request, via the Upgrade header field, for a change in the application protocol.
What it means
The HTTP 101 Switching Protocols response code indicates the server is switching to the protocol the client requested in its `Upgrade` header.
This is most commonly used when establishing a WebSocket connection. A client connects via standard HTTP/1.1 and requests to upgrade to the WebSocket protocol for full-duplex communication. Once the 101 is sent, the connection is no longer HTTP.
How it works
- 1The client sends an HTTP GET request with 'Connection: Upgrade' and 'Upgrade: websocket'.
- 2The server verifies the request (e.g., checks authentication, validates websocket keys).
- 3The server responds with '101 Switching Protocols'.
- 4The TCP connection remains open, but the protocol spoken over it changes from HTTP to WebSockets.
Why you're seeing this
- • The client sent a valid 'Upgrade' header and the server agreed to switch protocols.
How to fix it
- • If you see a WebSocket connection failing immediately after 101, ensure your load balancers/proxies (like Nginx or HAProxy) are configured to support protocol upgrades and aren't prematurely closing long-lived connections.
Framework Implementations
Node.js (ws)
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
// The 'ws' library automatically handles the 101 handshake internally.Nginx (Proxy config)
location /ws/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}Real-Life Scenarios
Use this when you are implementing a WebSocket server, Server-Sent Events (SSE) fallback, or upgrading an HTTP/1.1 connection to HTTP/2 via cleartext (h2c).
Real-time Chat Applications
A user opens a chat app. The client upgrades the HTTP connection to WebSockets to receive instant messages without polling.
Live Financial Tickers
Streaming live stock prices to a trading dashboard where milliseconds matter.
HTTP Transaction
1. Client Request
GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Version: 13
2. Server Response
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
SEO Implications
WebSockets and 101 responses are not crawled by search engines. Ensure any publicly indexable content is served via standard HTTP GET routes (200 OK) rather than over a WebSocket.