1001Ferramentas
📊 Dev

Range Header Parser

Decompose a Range header (bytes=0-499, bytes=-100, etc.) into individual ranges with start, end and size.

Range: asking for just part of a file

The Range header asks for a byte interval instead of the whole resource, and it is what underpins resuming an interrupted download and dragging a video's progress bar without fetching everything before it. The form is the unit, an equals sign, and the list of intervals. Paste the value and the page computes start, end and size for each interval requested.

The indices are inclusive at both ends, which is the number one source of off-by-one errors: bytes=0-499 asks for 500 bytes, not 499. And there is the suffix form, with the first number absent — bytes=-500 means the last 500 bytes of the file, not from the start to byte 500. Confusing the two returns the wrong chunk with no error at all.

The correct response to a satisfied Range is 206 with Content-Range stating which span was delivered and the total size. If the server ignores the request and answers 200 with the whole file, the client has to cope — which is why the server advertises the capability in Accept-Ranges before any request arrives.

Frequently asked questions

What happens if I ask past the end of the file?
The server should answer 416, meaning range not satisfiable, and report the real size in Content-Range. An interval starting inside but ending past the end is valid, though: the server delivers up to the last byte, with no error.
Does asking for several intervals at once work?
It works, and the response becomes multipart with one part per interval. In practice it sees little use, because assembling and reading multipart is more work than making two requests — and several servers and intermediaries refuse multiple intervals for exactly that reason.
How does the server know the file has not changed between chunks?
Through If-Range, which accompanies Range carrying the ETag or date received earlier. If the resource changed, the server answers 200 with the whole new content instead of 206 — which avoids stitching together chunks from two different versions and producing a corrupt file.

Related Tools