HTTP 501 Not Implemented

Overview

The HTTP 501 Not Implemented status code indicates that the server does not support the functionality required to fulfill the request. It suggests that the server lacks the capability to perform the requested operation.

Purpose

The HTTP 501 response is used when the server recognizes the request method but cannot fulfill it. This could be due to the server not supporting the functionality required for the request.

Usage

Client Behavior:

  1. Send Request: The client sends an HTTP request to the server with an unsupported or not implemented method.
  2. Receive Response: The client receives an HTTP 501 status code, indicating that the requested functionality is not supported.

Server Behavior:

  1. Recognize Method: The server recognizes the request method but lacks the capability to perform it.
  2. Send Response: The server sends a 501 Not Implemented response.

Scenarios

  • Unsupported Methods: When the client uses an HTTP method not supported by the server.
  • Future Functionality: The server may return 501 for methods it intends to support in the future.

Sequence Diagram

Illustrating the process for an HTTP 501 response:

sequenceDiagram
    participant Client
    participant Server as Web Server

    Note over Client: Step 1: Client sends a request with an unsupported method
    Client->>Server: UNSUPPORTED_METHOD /resource HTTP/1.1 (Step 1)

    Note over Server: Step 2: Server recognizes the method as not implemented
    Server->>Client: HTTP/1.1 501 Not Implemented (Step 2)
    Server->>Client: Allow: GET, POST

Curl Request and Response Example

Sending a request using Curl with an unsupported method:

curl -i -X UNSUPPORTED_METHOD http://example.com/resource
# Expected response: HTTP/1.1 501 Not Implemented
# Allow: GET, POST

PHP cURL Request and Response Example

PHP script using cURL to handle a 501 Not Implemented response:

<?php
$ch = curl_init('http://example.com/resource');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'UNSUPPORTED_METHOD');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 501) {
    echo "Not Implemented. Allowed methods: " . curl_getinfo($ch, CURLINFO_HEADER_OUT);
}
curl_close($ch);
?>

Python Request and Response Example

Python script sending a request with an unsupported method and handling a 501 Not Implemented response:

import requests
response = requests.request('UNSUPPORTED_METHOD', 'http://example.com/resource')
if response.status_code == 501:
    print("Not Implemented. Allowed methods:", response.headers['Allow'])

Apache Configuration for HTTP 501 Not Implemented

Configuring Apache to handle 501 errors and specify allowed methods:

# Apache Configuration Example
ErrorDocument 501 "Not Implemented"
Header always allow GET
Header always allow POST

NGINX Configuration for HTTP 501 Not Implemented

NGINX configuration for handling 501 errors and specifying allowed methods:

# NGINX Configuration Example
error_page 501 = /501.html;
location = /501.html {
    internal;
    add_header Allow "GET, POST";
}

HTTP 500 Internal Server Error HTTP 502 Bad Gateway


 

Free Weekly

Newsletter

Join my weekly newsletter for the latest in tech! You'll get neat coding tricks, trend updates, career advice, SaaS reviews, crypto, bitcoin, and financial tips. All straight to your inbox, designed to keep you ahead.