206 Partial Content
HTTP response status code 206 Partial Content is returned by the server to indicate that a HTTP request has been successfully completed and the message body contains the requested ranges of data.
When the 206 Partial Content status code is received, it is in response to a HTTP request that includes one or more Range HTTP headers. A Range HTTP header is used to specify which parts of the document the server to return and the server can optionally return the data as a multipart document.
If there is only one Range HTTP header specified then the Content-Length HTTP header is set to the entire document, the Content-Type HTTP header is set to the type of document, the Content-Range HTTP header will indicate which section is included, and the requested data will be contained in the message body.
In cases where multiple ranges are specified, the Content-Length HTTP header will indicate the total number of bytes in the message body. The initial Content-Type HTTP header will be set to
multipart/byteranges and subsequent Content-Type / Content-Range HTTP header pairs will describe the range that immediately follows. A server will not specify a Content-Range field in the initial HTTP header.
In multi-range requests, the server can optionally merge any of the ranges that overlap, or those that are separated by a gap that is less than the overhead required to send the subsequent range data. This is done for efficiency and it is important to consider because it means that receiving fewer HTTP requests than expected does not necessarily indicate an error. However, the opposite is not true; a server will not generate multiple ranges when only a single range is requested.
Aside from not being guaranteed to receive the same number of ranges that were requested, the order of them is not definite, either. A server is expected to make an effort to send ranges in the same order as the HTTP requests are received but it is not always practical.
Regardless of the number of ranges requested, the Content-Range HTTP header will include the total size of the resource. If it is unknown at the time the HTTP header is created then this will be denoted with an asterisk.
If the server is unable to return the range or ranges requested by the client, the server may return the 416 Range Not Satisfiable status code, or instead, return a 200 OK status code with the entire document in the message body.
Example of single-range retrieval
In this first example, the client requests a block of data inside of a video file, as specified by the Range header request field. The server returns the requested range, indicating it is an MP4-encoded video.
GET /videos/sample.mp4 HTTP/1.1 Host: www.example.ai Range: bytes=25000-75000
HTTP/1.1 206 Partial Content Content-Type: video/mp4 Content-Length: 25000 Content-Range: bytes 25000-75000/100000 <50,000 bytes of video data will follow>
Alternate response – when the total size was not known by the server
HTTP/1.1 206 Partial Content Content-Type: video/mp4 Content-Length: 25000 Content-Range: bytes 25000-75000/* <50,000 bytes of video data will follow>
Example of multi-range retrieval
In a case where more than one range is requested, the client will specify each of them in the HTTP request. These can be placed on different lines, or comma-delimited on the same line. A string separator will be given by the server to denote the end of the range data.
GET /videos/sample.mp4 HTTP/1.1 Host: www.example.ai Range: bytes=100-250 Range: bytes=1500-2000, 5000-5200
HTTP/1.1 206 Partial Content Content-Length: 850 Content-Type: multipart/byteranges; boundary=String_range_divider --String_range_divider
Content-Type: video/mp4 Content-Range: 100-250/75000 <150 bytes of video data will follow as the first range> --String_range_divider
Content-Type: video/mp4 Content-Range: 1500-2000/75000 <500 bytes of video data will follow as the second range> --String_range_divider
Content-Type: video/mp4 Content-Range: 5000-5200/75000 <200 bytes of video data will follow as the second range> --String_range_divider
Apache HttpComponents Core
HTTP response status code 206 Partial Content indicates that a HTTP request for one or more ranges of data has been successfully processed. The data will follow either as one or more sections within the response message body.