Switching Protocols

The transmission protocol is changed at the request of the client

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

The 101 Switching Protocols status code indicates that the server understands and is willing to comply with the client's request, via the Upgrade header field, for a change in the application protocol being used on this connection. The server MUST generate an Upgrade header field in the response that indicates which protocol(s) will be switched to immediately after the empty line that terminates the 101 Switching Protocols response. It is assumed that the server will only agree to switch protocols when it is advantageous to do so. For example, switching to a newer version of HTTP might be advantageous over older versions, and switching to a real-time, synchronous protocol might be advantageous when delivering resources that use such features.

Source / Quote by: The 101 Switching Protocols HTTP Status Code is specified by section 6.2.2 of RFC7231.

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:

Status code 101 Switching Protocols
URL: https://http-statuscode.com/errorCodeExample.php?code=101
Status: 101 Switching Protocols
Those: Network
IP address: XX.XX.XX.XX
Status code 101 Switching Protocols

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

Author: Tony Brüser
Author: Tony Brüser

Tony Brüser is an enthusiastic web developer with a penchant for HTTP status codes.