206 Partial Content: Serving Parts of a Resource
Range request from the client. It indicates that the server is returning only a portion of the resource, as specified in the Content-Range header. This is essential for resuming interrupted downloads, streaming video, and serving large files in chunks.
How Range Requests Work
A client sends a Range header to request specific bytes of a resource, for example:
If the server supports range requests, it responds with 206 Partial Content and a Content-Range header describing the returned range:
Common Use Cases
- Resuming downloads β if a download is interrupted, the client can request the remaining bytes with
Range: bytes=5000-. - Video streaming β video players request small byte ranges to seek to specific positions without downloading the entire file.
- Large file serving β CDNs and web servers use 206 to serve large files in chunks for better performance.
- Multiβpart ranges β a client can request multiple ranges at once:
Range: bytes=0-99, 200-299.
Required Headers for 206
| Header | Description | Example |
|---|---|---|
Content-Range | Indicates which bytes are being returned and the total size. | bytes 0-1023/1024000 |
Content-Length | The length of the returned range in bytes. | 1024 |
Content-Type | The MIME type of the resource. | video/mp4 |
Accept-Ranges | Sent in initial responses to indicate that range requests are supported. | bytes |
MultiβRange Response
When a client requests multiple ranges, the server may respond with a multipart/byteranges message:
Server Implementation Notes
- Support range requests β set
Accept-Ranges: bytesin your responses to indicate capability. - Validate ranges β ensure the requested ranges are within the resource's size.
- Handle unsatisfiable ranges β if the range is invalid, respond with 416 Range Not Satisfiable.
- Cache appropriately β 206 responses can be cached, but the cache must respect the range headers.
Frequently Asked Questions
Is 206 Partial Content cacheable?
Yes, but the cache must store the response with the specific byte range. When a later request asks for the same range, the cache can serve it. However, caching multiple ranges for the same resource can be complex.
What happens if the server doesn't support range requests?
The server will ignore the Range header and return the full resource with a 200 OK status. The client should be prepared to handle either 200 or 206.
Can I use 206 for dynamic content?
Yes, but you must ensure the content is generated consistently so that byte ranges are meaningful. For dynamically generated content, range requests may be impractical.