Module Spindle_http.Media_type

A media type, as Content-Type holds one (RFC 9110 §8.3.1): a type, a subtype and parameters.

Media_type.parse {|application/json; charset="utf-8"|}
= Ok
    {
      type_ = "application";
      subtype = "json";
      parameters = [ ("charset", "utf-8") ];
    }
type t = {
  1. type_ : string;
    (*

    lower-cased, as it is compared

    *)
  2. subtype : string;
    (*

    lower-cased

    *)
  3. parameters : (string * string) list;
    (*

    in the order given, each name lower-cased and each value as it came, a quoted string's escapes undone

    *)
}
val parse : string -> (t, string) Stdlib.result

A field's value as one media type, and nothing after it; a parameter given twice is an Error (RFC 6838 §4.3), in words for a log.

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

type/subtype, then each parameter as ; name=value, its value a quoted string where it is not a token, or Error for what parse would not read back as itself: a type or a name that is no token or is not lower-cased, a parameter twice, a value no quoted string can hold.

val equal : t -> t -> bool

The same type, subtype and parameters, in the same order.

val is_pattern : string -> bool

Whether a text is one matches reads: type/subtype, type/* or type/*+suffix, each a token, and no parameters.

val matches : string -> t -> bool

matches pattern t: whether t is of pattern -- type/subtype, type/* or type/*+suffix, application/*+json for application/ld+json -- compared without case, its parameters not compared. A pattern of none of these forms matches nothing.

val parameter : t -> string -> string option

The first value of the parameter named, whatever the name's case.