Module Http.Range

Range requests.

Support for range requests.

Byte ranges

type bytes =
  1. | First of int
    (*

    First given offset to last offset

    *)
  2. | Last of int
    (*

    At most last given n bytes.

    *)
  3. | Range of {
    1. first : int;
      (*

      First offset.

      *)
    2. last : int;
      (*

      Last offset.

      *)
    }

The type for byte range specifications. Offsets are zero-based and bounds are inclusive.

val eval_bytes : length:int -> bytes -> (int * int) option

eval_bytes ~length b given a representation length len and byte range b returns a concrete zero-based byte range or None if the range cannot be satisfied for length.

Ranges

type t =
  1. | Bytes of bytes list
    (*

    Byte ranges.

    *)
  2. | Other of string * string
    (*

    Range unit and value.

    *)

The type for ranges.

Converting

val decode : string -> (t, string) Stdlib.result

decode s decodes an HTTP Range value.

val encode : t -> string

encode r serializes r to a HTTP Range value. It's the client duty to make sure ranges are valid.

Predicates and comparisons

val equal : t -> t -> bool

equal tests ranges for equality.

val compare : t -> t -> int

compare is a total order on ranges compatible with equal.

Formatting

val pp : Stdlib.Format.formatter -> t -> unit

pp formats ranges for inspection.