Navigation
What do HTTP Status Code 101 mean?
The HTTP Status 101 (Switching Protocols) represents that the client has asked the server in order to change the protocols and the server has agreed to do so. In another word, It indicates that the server understands and is asking the client to send the request, via the Upgrade header field for the change in application protocols after the empty line terminates the 101 response.
Examples
WebSocket Protocol is one of the best examples of status code 101-Switching Protocol.
It uses an HTTP handshake while creating the connection, especially for security purposes.
WebSocket client starts the connection, then the first few bytes look like this :
GET /chat HTTP/1.1Host: server.example.comUpgrade: WebSocketConnection: UpgradeSec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==Origin: http://example.comSec-WebSocket-Protocol: chat, superchatSec-WebSocket-Version: 13 |
If the Server supports WebSocket, it will respond with HTTP status code101-Switching Protocols and then switch to the WebSocket protocol:
HTTP/1.1 101 Switching ProtocolsUpgrade:WebSocket connection: UpgradeSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=Sec-WebSocket-Protocol: chat |
Source:https://evertpot.com/http/101-switching-protocols
Upgrade
This header field provides a mechanism for transitions from HTTP/1.1 to some other protocol on the same connection. When the list of protocols is provided in the Upgrade header file, then the Upgrade field requests the server to switch to one or more of those protocols, before sending the final response. When the server wishes to continue using the current protocol on that connection, then it may ignore a received Upgrade header field.
Status
101 Switching Protocols |
Specifications
Specifications | Title |
RFC 7231,section 6.2.2:101 Switching Protocol | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content |
101 CODE REFERENCES
Rails HTTP Status Symbol | :switching_protocols |
Go HTTP Status Constant | http.StatusSwitchingProtocols |
Symfony HTTP Status Constant | Response::HTTP_SWITCHING_PROTOCOLS |
Python2 HTTP Status Constant | httplib.SWITCHING_PROTOCOLS |
Python3+ HTTP Status Constant | http.client.SWITCHING_PROTOCOLS |
Python3.5+ HTTP Status Constant | http.HTTPStatus.SWITCHING_PROTOCOLS |
Read more: HTTP Status Code 302 Found
FAQs
What is the example of the 101 Switching Protocols?
WebSocket protocol is one of the examples of 101 Switching Protocol.
Is WebSocket a protocol?
Yes, WebSocket is an independent TCP-based communication protocol. It provides full-duplex communication channels over a single TCP connection. Its connection with HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request.
What does HTTP Status Code 101 mean?
The HTTP Status 101 (Switching Protocols) represents that the client has asked the server in order to change the protocols and the server has agreed to do so. In another word, It indicates that the server understands and is asking the client to send the request, via the Upgrade header field for the change in application protocols after the empty line terminates the 101 response.
Conclusion
I hope this article was able to help you with your doubts and queries related to the HTTP status code 101-Switching Protocols. Still, if there are any queries related to this topic, feel free to ask in the comment section, we would be happy to assist you. Thank you.
Saurabh Chalise