http.range.parse

http.range

parse(value, size) -> first, last

Read a Range header value against a body of size bytes

Gives one of three answers:

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 =.