Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

methodtHttpServerResponse.SendFileRange

function SendFileRange(const aPhysicalFile: string; const aRangeHeader: string): Integer;
SendFile, but honouring a Range header - and sending ONLY the octets the range asks for.

THIS IS THE ONE TO USE FOR ANYTHING LARGE. Like SendFile it keeps the file open and the wire session reads it as it sends, so a 200 MB download is never 200 MB of memory; unlike SendFile it lets a client that lost its connection ask for the rest instead of starting again.

Pass the request's Range header value, or '' when there is none.

What it sets, in each of the three outcomes:

no range 200, the whole file, Accept-Ranges: bytes
a range 206, that window, Content-Range: bytes o-e/total
unsatisfiable 416, EMPTY body, Content-Range: bytes * / total

The 416 body is deliberately empty. A 416 that carries the whole file is a contradiction - the status says "I could not give you what you asked for" - and it is the failure mode that makes a client's retry loop download the representation repeatedly.

Accept-Ranges: bytes is set in every case, including the 416, because it describes the resource and not the outcome.

Answers the status code it set, so a caller can log it.