101 101 Switching Protocols
The server is switching protocols as requested by the client via the Upgrade header.
What Is This?
The HTTP 101 Switching Protocols status code indicates that the server understands and accepts the client's request to switch to a different protocol as specified in the Upgrade header. This is primarily used for WebSocket connections, where the client requests an upgrade from HTTP to the WebSocket protocol.
Common Causes
WebSocket client sending an Upgrade: websocket request
Server accepting a protocol upgrade from HTTP/1.1 to HTTP/2
Custom protocol negotiation between client and server
Examples
Use the WebSocket API in clients and the 'ws' library or built-in HTTP server in Node.js to handle 101 responses.
// Client-side (browser)
const ws = new WebSocket('wss://example.com/socket')
ws.onopen = () => console.log('Connected')
// Server-side (Node.js)
import { WebSocketServer } from 'ws'
const wss = new WebSocketServer({ port: 8080 })
wss.on('connection', (ws) => {
ws.send('Hello from server')
})If the server responds with a standard HTTP status (not 101), the upgrade failed. The client should fall back to standard HTTP communication or retry with different protocol options.
Related Entries
More from this reference:
Frequently Asked Questions
What protocols can be switched to?
The most common protocol switch is to WebSocket (Upgrade: websocket). Other protocols include h2c (HTTP/2 over cleartext) and custom application protocols. The server must support the requested protocol.
Can proxies handle 101 Switching Protocols?
Many proxies do not support the 101 response and may drop the connection or prevent the upgrade. For WebSocket applications, use ports 80/443 and ensure load balancers are configured for WebSocket passthrough.