Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

ParseByteRange

function ParseByteRange(const aRangeHeader: string; aTotalSize: Int64; out aOffset, aLength: Int64): tRangeVerdict;
Parses an RFC 9110 Range header against a known representation size.

ONLY 'bytes' IS UNDERSTOOD, and only a single range. That is a deliberate reading of the specification rather than a shortcut: a server MAY ignore a Range header it does not wish to honour, and answering 200 with the whole representation is always correct. What is NOT correct - and is the trap a hand-rolled parser usually falls into - is to answer 206 carrying only the FIRST of several requested ranges, because the client asked for all of them and has no way to discover it did not get them. A multi-range request therefore answers rvNone here, and the caller sends the whole thing.

THE THREE FORMS, all of which occur in the wild:

bytes=0-499 the first 500 octets
bytes=500- from 500 to the end
bytes=-500 the LAST 500 octets - a suffix length, not a start

Answers rvUnsatisfiable only when the range is well-formed and entirely past the end, which is the only case RFC 9110 lets a server answer 416. A range that merely overshoots the end is clamped and satisfiable: 'bytes=0-99999' against a 10-octet file is the first 10 octets, not an error.

aOffset/aLength are meaningful only for rvSingle. aTotalSize of 0 makes every range unsatisfiable, which is what lets a caller answer 416 for an empty representation without special-casing it.