101
Switching Protocols
General explanation of the 101 status code
Imagine you are in a restaurant and want to order a drink. The waiter comes up to you and asks for your order. You say, "I'd like a glass of water, but if you have fresh orange juice, I'd prefer that." Here you are basically giving the waiter two options and letting them know you are flexible. The request to switch protocols works similarly.
When a web browser or other client tool sends a request to a server, the client may suggest switching to a different communication protocol because it believes that other protocol would be more efficient or better suited. For example, a client originally using an HTTP connection might suggest switching to WebSockets to provide an always-open connection for real-time data.
When the server accepts this suggestion, it responds with status code 101 Switching Protocols to tell the client, "All right! Let's switch protocols." From that point on, communication between the client and server continues using the new, agreed-upon protocol.
Specification of the HTTP status code 101
Source / Quote by: The 101 Switching Protocols HTTP Status Code is specified by section 6.2.2 of RFC7231.
HTTP-Protocol
How to throw a 101 statuscode with PHP?
To throw the HTTP status code 101 on a web page, the PHP function http_response_code can be used. The syntax is as follows: http_response_code(101) (PHP 5 >= 5.4.0, PHP 7, PHP 8)
Test the 101 HTTP status code
In order to be able to display the HTTP status code (in this case 101 Switching Protocols) and other information on the client side, the development console must be opened with F12. Afterwards you have to navigate to the tab "Network". Now you can open the page, in the network tab you should see the web page (example index.php). This must be selected and then the Herder section must be selected. Here the user will see the following result:
URL: https://http-statuscode.com/errorCodeExample.php?code=101
Status: 101 Switching Protocols
Those: Network
IP address: XX.XX.XX.XX
Browser compatibility of the 101 status code
Chrome | no data |
Edge | no data |
Firefox | no data |
Opera | no data |
Safari | no data |
Chrome Android | no data |
Firefox for Android | no data |
Opera Android | no data |
Safari on iOS | no data |
Internet | no data |
WebView Android | no data |
Constants in programming languages
HttpStatusCode.SwitchingProtocols
http.StatusSwitchingProtocols
Response::HTTP_SWITCHING_PROTOCOLS
httplib.SWITCHING_PROTOCOLS
http.client.SWITCHING_PROTOCOLS
http.HTTPStatus.SWITCHING_PROTOCOLS
:switching_protocols
HttpServletResponse.SC_SWITCHING_PROTOCOLS