Range
Description
The Range
request header allows a client to request only a specific portion of
a resource instead of downloading the entire content. This is particularly
useful for large files, such as videos, PDFs, or software downloads, as it
enables partial content retrieval and supports resumable downloads.
When a server supports range requests, it responds with a 206 Partial Content
status and includes the Content-Range
response header to indicate the returned
portion of the resource. If the server does not support range requests, it
ignores the Range
header and returns a 200 OK
response with the full
resource.
Syntax
The Range
header follows this syntax:
Where:
- <unit>
specifies the unit of measurement (typically bytes
).
- <start>
is the zero-based starting position of the requested range.
- <end>
is the optional ending position of the requested range (inclusive).
Examples:
Range: bytes=0-499 # Request the first 500 bytes
Range: bytes=500-999 # Request bytes 500 through 999
Range: bytes=1000- # Request from byte 1000 to the end of the resource
Range: bytes=-500 # Request the last 500 bytes of the resource
Examples
Requesting a Partial Content Download
A client requests the first 500 bytes of a large file.
Client Request:
Server Response (If Range is Supported):
HTTP/1.1 206 Partial Content
Content-Range: bytes 0-499/10000
Content-Length: 500
Content-Type: application/zip
[First 500 bytes of the file]
Resuming a Download
A client resumes an interrupted download by requesting bytes from position 2000 onward.
Client Request:
Server Response:
HTTP/1.1 206 Partial Content
Content-Range: bytes 2000-999999/1000000
Content-Length: 998000
Content-Type: video/mp4
[Bytes from 2000 onward]
Requesting Multiple Ranges
A client requests multiple byte ranges within a resource.
Client Request:
Server Response:
HTTP/1.1 206 Partial Content
Content-Type: multipart/byteranges; boundary=boundary1234
--boundary1234
Content-Range: bytes 0-99/1000
[First 100 bytes]
--boundary1234
Content-Range: bytes 200-299/1000
[Bytes 200 to 299]
--boundary1234--
If the server does not support multiple ranges, it may respond with 200 OK
and
send the full resource instead.
Summary
The Range
request header is a powerful tool for optimizing bandwidth usage,
enabling partial content retrieval, and supporting resumable downloads. It is
particularly useful for large files and streaming applications. However, not all
servers support range requests, so clients should handle cases where a 200 OK
response is returned instead of 206 Partial Content
. When combined with the
Accept-Ranges
response header, Range
helps improve download efficiency and
user experience.