HTTP 206 Partial Content
Overview
The HTTP 206 Partial Content
status code indicates that the server is successfully fulfilling a range request for a portion of the requested resource.
Purpose
The HTTP 206 response is typically used in response to a client request that includes a Range
header, indicating that only a part of the resource is needed. This is commonly used in scenarios like resuming downloads or streaming media.
Usage
Client Behavior:
- Send Range Request: The client sends an HTTP request with a
Range
header specifying the desired part of the resource. - Receive Response: The client receives the HTTP 206 status code along with the specified range of the content.
Server Behavior:
- Process Range Request: The server processes the request and identifies the specified range of the resource.
- Send Response: The server sends a
206 Partial Content
response with the specified portion of the resource.
Scenarios
- Resuming Downloads: Allowing clients to resume interrupted downloads without re-downloading the entire resource.
- Media Streaming: Used in video or audio streaming services to deliver portions of a file as requested by the client.
Sequence Diagram
Illustrating the request and response process for HTTP 206:
sequenceDiagram participant Client participant Server as Web Server Note over Client: Client requests a specific range Client->>Server: GET /video.mp4 HTTP/1.1 Client->>Server: Range: bytes=1000-2000 Note over Server: Server sends the requested range Server->>Client: HTTP/1.1 206 Partial Content Server->>Client: Content-Range: bytes 1000-2000/100000
Curl Request and Response Example
Requesting a specific range of content using Curl:
curl -i -H "Range: bytes=1000-2000" http://example.com/video.mp4
# Expected response: HTTP/1.1 206 Partial Content
# Content-Range: bytes 1000-2000/100000
PHP cURL Request and Response Example
PHP script using cURL to request a specific range of content:
<?php
$ch = curl_init('http://example.com/video.mp4');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RANGE, '1000-2000');
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 206) {
echo "Partial content received.";
}
curl_close($ch);
?>
Python Request and Response Example
Python script to send a range request and handle a 206 Partial Content response:
import requests
headers = {'Range': 'bytes=1000-2000'}
response = requests.get('http://example.com/video.mp4', headers=headers)
if response.status_code == 206:
print("Partial content received")
Apache Configuration for HTTP 206 Partial Content
Configuring Apache to support range requests for partial content delivery:
<VirtualHost *:80>
ServerName example.com
# Enable mod_headers for Range requests
<IfModule mod_headers.c>
Header set Accept-Ranges bytes
</IfModule>
# Other configurations...
</VirtualHost>
NGINX Configuration for HTTP 206 Partial Content
Setting up NGINX to handle HTTP range requests for partial content delivery:
server {
listen 80;
server_name example.com;
location / {
# Ensure NGINX supports Range requests
proxy_pass http://backend_server;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
# Additional configurations...
}
}
HTTP 205 Reset Content HTTP 207 Multi-Status (WebDAV)