HTTP 416 Requested Range Not Satisfiable

Overview

The HTTP 416 Range Not Satisfiable status code indicates that the server cannot serve the requested byte range from the resource. This response is typically sent when the client requests a range of bytes (using the Range header) that is not available within the target resource’s size.

Purpose

The HTTP 416 response is used to notify the client that the requested range of bytes cannot be provided, often because the range is outside the size of the target resource.

Usage

Client Behavior:

  1. Send Request with Byte Range: The client sends an HTTP request including a Range header for a specific byte range.
  2. Receive Response: The client receives the HTTP 416 status code if the requested range is not satisfiable.

Server Behavior:

  1. Evaluate Byte Range: The server checks if the requested byte range falls within the size of the resource.
  2. Send Response: If the range is not available, the server responds with a 416 Range Not Satisfiable status code.

Scenarios

  • Partial Content Requests: When clients use range requests to download portions of large files.
  • Invalid Range Requests: Requests for byte ranges that exceed the size of the resource.

Sequence Diagram

Illustrating the process for an HTTP 416 response:

sequenceDiagram
    participant Client
    participant Server as Web Server

    Note over Client: Client requests a specific byte range
    Client->>Server: GET /resource HTTP/1.1
    Client->>Server: Range: bytes=5000-10000
    Note over Server: Server evaluates the range
    Server->>Client: HTTP/1.1 416 Range Not Satisfiable

Curl Request and Response Example

Requesting a byte range using Curl:

curl -i -H "Range: bytes=5000-10000" http://example.com/resource
# Expected response: HTTP/1.1 416 Range Not Satisfiable

PHP cURL Request and Response Example

PHP script using cURL to handle a 416 Range Not Satisfiable response:

<?php
$ch = curl_init('http://example.com/resource');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Range: bytes=5000-10000'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 416) {
    echo "Requested range not satisfiable.";
}
curl_close($ch);
?>

Python Request and Response Example

Python script to send a GET request with a byte range and handle a 416 response:

import requests
headers = {'Range': 'bytes=5000-10000'}
response = requests.get('http://example.com/resource', headers=headers)
if response.status_code == 416:
    print("Requested range not satisfiable")

Apache Configuration for HTTP 416 Range Not Satisfiable

Configuring Apache to support byte range requests:

<VirtualHost *:80>
    ServerName example.com
    # Ensure mod_headers is enabled for Byte Range support
    # Apache handles byte ranges by default if the module is enabled
</VirtualHost>

NGINX Configuration for HTTP 416 Range Not Satisfiable

Setting up NGINX to handle range requests:

server {
    listen 80;
    server_name example.com;
    location /resource {
        # NGINX supports byte ranges by default
        # Additional configurations as needed
    }
}

HTTP 415 Unsupported Media Type HTTP 417 Expectation Failed


 

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.