HTTP 426 Upgrade Required
Overview
The HTTP ~426 Upgrade Required~ status code indicates that the client should switch to a different protocol, as the current protocol is considered insufficient by the server.
Purpose
The HTTP 426 response is used to inform the client that it needs to upgrade to a different protocol for communication with the server.
Usage
Client Behavior:
- Send Request: The client sends an HTTP request to the server.
- Receive Response: The client receives the HTTP 426 status code, indicating that an upgrade to a different protocol is required.
- Upgrade Protocol: The client switches to the specified protocol for further communication.
Server Behavior:
- Evaluate Protocol: The server determines that the current protocol is insufficient for the requested resource.
- Send Response: The server responds with a ~426 Upgrade Required~ status, specifying the required protocol.
Scenarios
- Protocol Upgrade: Used when the server requires the client to upgrade to a more secure or advanced protocol.
Sequence Diagram
Illustrating the process for an HTTP 426 response:
sequenceDiagram
    participant Client
    participant Server as Web Server
    Note over Client: Step 1: Client sends a request
    Client->>Server: HTTP Request (Step 1)
    Note over Server: Step 2: Server evaluates protocol
    Server->>Client: HTTP/1.1 426 Upgrade Required (Step 2)
    Server->>Client: Upgrade: TLS/1.3 (Step 3)Curl Request and Response Example
Sending a request that requires an upgrade using Curl:
curl -i http://example.com/resource
# Expected response: HTTP/1.1 426 Upgrade Required
# Upgrade: TLS/1.3PHP cURL Request and Response Example
PHP script using cURL to handle a 426 Upgrade Required response:
<?php
$ch = curl_init('http://example.com/resource');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 426) {
    $upgradeProtocol = curl_getinfo($ch, CURLINFO_UPGRADE);
    echo "Upgrade required. Upgrade to: $upgradeProtocol";
}
curl_close($ch);
?>
Python Request and Response Example
Python script to handle a 426 Upgrade Required response:
import requests
response = requests.get('http://example.com/resource')
if response.status_code == 426:
    upgrade_protocol = response.headers['Upgrade']
    print(f"Upgrade required. Upgrade to: {upgrade_protocol}")Apache Configuration for HTTP 426 Upgrade Required
Configuring Apache to handle scenarios where the server requires a protocol upgrade:
<VirtualHost *:80>
    ServerName example.com
    <Location "/resource">
        # Additional configuration to evaluate protocol
        # ...
        # Return 426 Upgrade Required with Upgrade header
        Header always set Upgrade "TLS/1.3"
        ErrorDocument 426 "HTTP/1.1 426 Upgrade Required"
    </Location>
</VirtualHost>NGINX Configuration for HTTP 426 Upgrade Required
Setting up NGINX to handle scenarios where the server requires a protocol upgrade:
server {
    listen 80;
    server_name example.com;
    location /resource {
        # Additional configuration to evaluate protocol
        # ...
        # Return 426 Upgrade Required with Upgrade header
        add_header Upgrade "TLS/1.3";
        return 426 "HTTP/1.1 426 Upgrade Required";
    }
}HTTP 425 Reserved for WebDAV HTTP 428 Precondition Required