package cohttp

  1. Overview
  2. Docs

Module Cohttp.HeaderSource

Sourcetype t

Map of HTTP header key and value(s) associated with them. Since HTTP headers can contain duplicate keys, this structure can return a list of values associated with a single key.

include Ppx_sexp_conv_lib.Sexpable.S with type t := t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval init : unit -> t

Construct a fresh, empty map of HTTP headers.

Sourceval is_empty : t -> bool

Test whether HTTP headers are empty or not.

Sourceval init_with : string -> string -> t

Construct a fresh map of HTTP headers with a single key and value entry.

Sourceval add : t -> string -> string -> t

Add a key and value to an existing header map.

Sourceval add_list : t -> (string * string) list -> t

Add multiple key and value pairs to an existing header map.

Sourceval add_multi : t -> string -> string list -> t

Add multiple values to a key in an existing header map.

Sourceval add_opt : t option -> string -> string -> t

Given an optional header, either update the existing one with a key and value, or construct a fresh header with those values if the header is None.

Sourceval add_unless_exists : t -> string -> string -> t

Given a header, update it with the key and value unless the key is already present in the header.

Sourceval add_opt_unless_exists : t option -> string -> string -> t

add_opt_unless_exists h k v updates h with the key k and value v unless the key is already present in the header. If h is None then a fresh header is allocated containing the key k and the value v.

Sourceval remove : t -> string -> t

Remove a key from the header map and return a fresh header set. The original header parameter is not modified.

Sourceval replace : t -> string -> string -> t

Replace the value of a key from the header map if it exists, otherwise it adds it to the header map. The original header parameter is not modified.

Sourceval update : t -> string -> (string option -> string option) -> t

update h k f returns a map containing the same headers as h, except for the header k. Depending on the value of v where v is f (get h k), the header k is added, removed or updated. If v is None, the header is removed if it exists; otherwise, if v is Some z then k is associated to z in the resulting headers. If k was already associated in h to a value that is physically equal to z, h is returned unchanged. Similarly as for get, if the header is one of the set of headers defined to have list values, then all of the values are concatenated into a single string separated by commas and passed to f, while the return value of f is split on commas and associated to k. If it is a singleton header, then the first value is passed to f and no concatenation is performed, similarly for the return value. The original header parameters are not modified.

Sourceval mem : t -> string -> bool

Check if a key exists in the header.

Sourceval compare : t -> t -> int

Structural comparison of two Header values.

Sourceval get : t -> string -> string option

Retrieve a key from a header. If the header is one of the set of headers defined to have list values, then all of the values are concatenated into a single string separated by commas and returned. If it is a singleton header, then the first value is selected and no concatenation is performed.

Sourceval get_multi : t -> string -> string list

Retrieve all of the values associated with a key

Sourceval iter : (string -> string list -> unit) -> t -> unit
Sourceval map : (string -> string list -> string list) -> t -> t
Sourceval fold : (string -> string -> 'a -> 'a) -> t -> 'a -> 'a
Sourceval of_list : (string * string) list -> t
Sourceval to_list : t -> (string * string) list
Sourceval to_lines : t -> string list

Return header fieds as a list of lines. Beware that each line ends with "\r\n" characters.

Sourceval to_frames : t -> string list

Same as to_lines but lines do not end with "\r\n" characters.

Sourceval to_string : t -> string
Sourceval get_content_range : t -> Int64.t option
Sourceval get_media_type : t -> string option
Sourceval get_connection_close : t -> bool
Sourceval get_acceptable_media_ranges : t -> (Accept.media_range * Accept.p list) Accept.qlist
Sourceval get_acceptable_charsets : t -> Accept.charset Accept.qlist
Sourceval get_acceptable_encodings : t -> Accept.encoding Accept.qlist
Sourceval get_acceptable_languages : t -> Accept.language Accept.qlist
Sourceval get_transfer_encoding : t -> Transfer.encoding
Sourceval add_transfer_encoding : t -> Transfer.encoding -> t
Sourceval add_authorization : t -> Auth.credential -> t
Sourceval get_authorization : t -> Auth.credential option
Sourceval add_authorization_req : t -> Auth.challenge -> t
Sourceval is_form : t -> bool
Sourceval get_location : t -> Uri.t option
Sourceval user_agent : string

The User-Agent header used by this library, including the version of cohttp.

Sourceval prepend_user_agent : t -> string -> t

The User-Agent header used by this library, including the version of cohttp.

Prepend user_agent to the product token already declared in the "User-Agent" field (if any).

Sourceval connection : t -> [ `Keep_alive | `Close | `Unknown of string ] option
Sourceval pp_hum : Format.formatter -> t -> unit

Human-readable output, used by the toplevel printer

OCaml

Innovation. Community. Security.