http.range

index · http

Overview

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.

Functions

NameSignature
parseparse(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:

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