HTTP 451 Unavailable For Legal Reasons
Overview
The HTTP 451 Unavailable For Legal Reasons
status code indicates that the server is refusing to provide the requested resource due to legal reasons. It is often used when content is censored or restricted for legal considerations.
Purpose
The primary purpose of the HTTP 451 response is to inform the client that access to the requested resource is restricted or blocked for legal reasons.
Usage
Client Behavior:
- Send Request: The client sends an HTTP request to access a specific resource.
- Receive Response: The client receives the HTTP 451 status code, indicating legal restrictions.
Server Behavior:
- Legal Restrictions: The server determines that access to the resource is legally restricted.
- Send Response: The server sends a
451 Unavailable For Legal Reasons
response, providing information about the legal restrictions.
Scenarios
- Censorship: When a government or legal authority restricts access to certain content.
- Copyright Violation: Blocking access to copyrighted material without proper authorization.
Sequence Diagram
Illustrating the process for an HTTP 451 response:
sequenceDiagram participant Client participant Server as Web Server Note over Client: Client attempts to access a restricted resource Client->>Server: GET /restricted-resource HTTP/1.1 Note over Server: Server identifies legal restrictions Server->>Client: HTTP/1.1 451 Unavailable For Legal Reasons
Curl Request and Response Example
Attempting to access a restricted resource using Curl:
curl -i http://example.com/restricted-resource
# Expected response: HTTP/1.1 451 Unavailable For Legal Reasons
PHP cURL Request and Response Example
PHP script using cURL to handle a 451 Unavailable For Legal Reasons response:
<?php
$ch = curl_init('http://example.com/restricted-resource');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 451) {
echo "Resource unavailable for legal reasons.\n";
}
curl_close($ch);
?>
Python Request and Response Example
Python script to send a request and handle a 451 Unavailable For Legal Reasons response:
import requests
response = requests.get('http://example.com/restricted-resource')
if response.status_code == 451:
print("Resource unavailable for legal reasons.")
Apache Configuration for HTTP 451 Unavailable For Legal Reasons
Configuring Apache to return a 451 response for specific resources:
<VirtualHost *:80>
ServerName example.com
<Location "/restricted-resource">
ErrorDocument 451 /451.html
</Location>
</VirtualHost>
NGINX Configuration for HTTP 451 Unavailable For Legal Reasons
Setting up NGINX to return a 451 response for certain resources:
server {
listen 80;
server_name example.com;
location /restricted-resource {
error_page 451 /451.html;
}
}
HTTP 450 Blocked by Windows Parental Controls (Microsoft) HTTP 499 Client Closed Request (Nginx)