101 Switching Protocols
101 Switching Protocols, an informative HTTP response code sent by the server, signifying that the HTTP session can proceed and a transition to a new protocol is taking place.
The HTTP status code 101 Switching Protocols is an informative response sent by the server, signifying that the HTTP session can proceed and a transition to a new protocol is taking place.
This response is triggered when the client includes the Upgrade HTTP header request field, along with the mandatory HTTP request header Connection: upgrade.
By incorporating this status code and following the specified protocol upgrade, the client and server can seamlessly switch to a new communication mechanism, facilitating enhanced data exchange and ensuring a smoother browsing experience for users.
When the Client uses the Upgrade request header field, he wants the server to adopt an alternative protocol for the remainder of the HTTP session. This field allows multiple HTTP protocols to be listed on a single line, comma-delimited, to descend preference, with the HTTP protocol version being optional.
The HTTP request is triggered when it's beneficial to use a different protocol, such as accessing features provided by newer HTTP versions. However, the upgrade is currently limited to HTTP/1.1, and clients cannot enforce server protocol changes; instead, it remains optional, and the server responds with a 200 OK if the Upgrade header request field is disregarded.
While the server cannot mandate HTTP protocol upgrades for clients, it possess the authority to reject HTTP requests if clients don't fulfill its criteria. When a client employs an unsupported HTTP protocol in their request, the server may respond with the status code 426 Upgrade Required. However, if the client follows the server's instructions for using the HTTP protocol, subsequent requests can be acknowledged and processed accordingly.
Upgrade from HTTP/1.1 to HTTP/2 or HTTP/3
Request
GET /index.html HTTP/1.1
Host: www.example.com
Connection: upgrade
Upgrade: HTTP/3, HTTP/2
Response
HTTP/1.1 101 Switching Protocols
Upgrade: HTTP/2
Connection: upgrade
Upgrade from HTTP/1.1 to use WebSockets
Request
GET /index.html HTTP/1.1
Host: www.example.re
Connection: upgrade
Upgrade: websocket
Response
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: upgrade
The HTTP response status code 101 Switching Protocols indicates a successful transition to a new protocol for the ongoing HTTP session.
Clients requesting a protocol switch by including the "Upgrade" and "Connection" headers can proceed with the new protocol, provided it is supported by the server.