HttpSendStreamRange
function HttpSendStreamRange(const aResponse: iHttpResponse; aStream: TStream; const aRangeHeader: string; aOwns: Boolean; const aContentType: string = ''): Integer;
Range over a STREAM the caller already holds - SendFileRange for a source that is not a path. THE ONE RANGE IMPLEMENTATION: SendFileRange opens its file and calls this.
Why it exists: SendFileRange takes a physical path and opens it, and a caller serving out of a verified stFileJail handle must not re-open by name - the handle IS the containment proof, and re-resolving the path is the check-then-use the jail was written to remove. Until this function the choice was race-free serving (jail stream + SetContentStream) OR ranges (path + SendFileRange), never both. Now: open through the jail, hand the stream here.
Behaviour is SendFileRange's exactly, on the same status codes: 200 for no usable Range (whole stream), 206 with Content-Range for one satisfiable range (that window only), 416 with an EMPTY body and 'Content-Range: bytes */<size>' past the end. 'Accept-Ranges: bytes' on every outcome, because it describes the resource, not the answer. Answers the status it set.
aStream's Size is the representation length. WITH aOwns THE STREAM IS HANDED TO THE RESPONSE when the response supports iHttpResponseSource (this unit's does): the 200 or 206 body is then a window onto it, read as it is sent and never copied, and the response frees it afterwards. On a 416, and on a response without that interface, it is freed before return as before. WITHOUT aOwns the window is COPIED into the body - the stream stays the caller's and may be gone when the handler returns - so a large source served that way is a large allocation. aContentType is set on 200 and 206 when non-empty and left alone when '' - a stream has no extension to derive one from, so the caller decides; a 416 carries neither type nor body.
A standalone function rather than a new iHttpResponse member: that interface is shipped, and a new method on it would break every implementation outside this unit (the iHttpPrefixRouter reasoning). It uses only the public contract
- SetHeader, SetContentType, SetContentStream, SetContent, SetStatus, and iHttpResponseSource where Supports finds it - so it works against any iHttpResponse.