The Range request header, read against a body of a known size (RFC 9110).
http.server calls parse for a string body whose handler set
accept-ranges: bytes. A handler that streams its body calls it itself,
and answers 206 or 416 with its own content-range.
| Name | Signature |
|---|---|
| parse | parse(value, size) -> first, last |
parse(
value,size) ->first,last
Read a Range header value against a body of size bytes
Gives one of three answers:
first, last: the byte range to send, zero based and inclusive, ready
for content-range: bytes first-last/size. In Lua the slice is
body:sub(first + 1, last + 1).nil, "unsatisfiable": a well-formed range that holds no byte of the
body. The answer is a 416.nil: no range to honour. The answer is the whole body.It reads the three forms bytes=a-b, bytes=a- and bytes=-n, the last
n bytes. A b past the end is cut to the end. An n longer than the body
gives the whole body.
The plain nil covers a value that is not a string, a malformed one, a unit
that is not bytes, a greater than b, and a list of several ranges.
RFC 9110 lets a server ignore a Range header, and no media player asks for
a list.
A first at or past the end is unsatisfiable, and so is bytes=-0.
A body of zero bytes has no byte to name in a content-range. a-b and
a- are unsatisfiable against it. -n gives the plain nil, and the
caller sends the empty body.
The unit matches in any letter case. Spaces may surround the value and
follow the =.