The HTTP 426 Upgrade Required
status code indicates that the server refuses to process the request using the current protocol but is willing to do so if the client upgrades to a different protocol. This is often used to enforce the use of a more secure protocol, such as upgrading from HTTP to HTTPS.
Key Points
- The server requires the client to switch to a different protocol to complete the request.
- Commonly used to enforce the use of secure protocols (e.g., upgrading from HTTP to HTTPS).
- The server includes an
Upgrade
header in the response to specify the required protocol.
Common Causes
- Protocol Upgrade Required: The server requires the client to upgrade to a more secure or advanced protocol (e.g., HTTP to HTTPS, HTTP/1.1 to HTTP/2).
- Security Policies: The server enforces a policy that mandates the use of secure communication.
- Deprecated Protocols: The server no longer supports the protocol used by the client.
How to Fix
- Client-Side Fix:
- Upgrade to the protocol specified in the server’s
Upgrade
header. - For example, switch from HTTP to HTTPS by changing the request URL from
http://
tohttps://
. - Ensure the client supports the required protocol.
- Server-Side Fix:
- Return a
426 Upgrade Required
status code with anUpgrade
header specifying the required protocol. - Provide clear instructions in the response body or headers about the required upgrade.
- Log protocol upgrade requests for monitoring and debugging.
Example
If a client sends a request over HTTP but the server requires HTTPS, the server might respond:
HTTP/1.1 426 Upgrade Required
Upgrade: TLS/1.2, HTTP/1.1
Connection: Upgrade
Content-Type: application/json
{
"error": "Upgrade Required",
"message": "The server requires the request to be made over HTTPS."
}
Client-Side Handling
- Check the
Upgrade
header in the response to determine the required protocol. - Modify the request to use the specified protocol (e.g., switch from HTTP to HTTPS).
- Ensure the client application supports the required protocol.
Server-Side Handling
- Return a
426 Upgrade Required
status code when the client must upgrade to a different protocol. - Include an
Upgrade
header specifying the required protocol(s). - Provide clear instructions in the response body or headers to guide the client.