101

HTTP 101 Switching Protocols

1xx Informational

1xx Informational RFC 7231, Section 6.2.2

What is HTTP 101 Switching Protocols?

The 101 (Switching Protocols) status code indicates the server understands and is willing to comply with the client's request to switch protocols. The server will include an Upgrade header to indicate which protocol it is switching to. This is the cornerstone of WebSocket connections — when a client sends an Upgrade: websocket header, the server responds with 101 to confirm the protocol switch from HTTP to WebSocket, enabling real-time bidirectional communication.

Common Use Cases

  • WebSocket upgrade handshake
  • HTTP/2 protocol upgrade
  • Adding real-time communication to web applications

Usage Example

When building a real-time chat application, your JavaScript client uses the WebSocket API to initiate a connection. The browser sends an HTTP Upgrade request, and if the server supports WebSockets, it responds with 101 Switching Protocols. From that point forward, the connection operates as a WebSocket rather than HTTP.

// JavaScript - Client-side WebSocket handshake
const ws = new WebSocket('wss://api.example.com/chat');
ws.onopen = () => console.log('Connected (101 Switching Protocols)');
ws.onmessage = (e) => console.log('Received:', e.data);

Common Mistakes

⚠️

Mistake: Trying to send HTTP requests after a 101 protocol switch

Fix: Once the protocol switches (e.g., to WebSocket), the connection no longer speaks HTTP. Use the upgraded protocol's framing for all subsequent communication.

⚠️

Mistake: Forgetting to validate the Upgrade header on the server side

Fix: Always verify that the Upgrade header contains a protocol your server supports (e.g., "websocket"). Respond with 426 Upgrade Required if the requested protocol is not supported.

Last updated: 21 Jun 2026