Module Webs.Http

HTTP nuts and bolts.

Just types, values, codecs and protocol logic fragments.

References.

Codecs

Encodings

module Base64 : sig ... end

base64 and base64url codecs.

module Pct : sig ... end

Percent-encoding codec.

module Digits : sig ... end

HTTP digits codec.

Names

HTTP often requires to perform US-ASCII case insensitive comparisons on HTTP tokens. Values of type name represent US-ASCII lowercased HTTP tokens.

type name = private string

The type for lowercased HTTP tokens. In particular header field-names.

module Name : sig ... end

Names.

Versions

type version = int * int

The type for HTTP versions. Both integers must be in the interval [0;9].

module Version : sig ... end

HTTP versions.

Methods

type meth = [
| `GET(*

GET

*)
| `HEAD(*

HEAD

*)
| `POST(*

POST

*)
| `PUT(*

PUT

*)
| `DELETE(*

DELETE

*)
| `CONNECT(*

CONNECT

*)
| `OPTIONS(*

OPTIONS

*)
| `TRACE(*

TRACE

*)
| `PATCH(*

PATCH '

*)
| `Other of string(*

other token

*)
]

The type for HTTP request methods.

module Meth : sig ... end

HTTP request methods

Paths and queries

type fpath = string

The type for file paths.

type path = string list

The type for absolute URI paths represented as non-empty lists of percent-decoded path segments. The empty list denotes the absence of a path.

Path segments can be empty "". The root path / is represented by the list [""] and /a by ["a"], see more examples here.

WARNING. You should never concatenate these segments with a separator to get a file path because they may contain stray percent-decoded directory separators. Use the function Path.to_absolute_filepath to interpret paths as file paths.

module Path : sig ... end

Paths.

type query

The type for queries as key-values maps. Both keys and values are properly decoded. Note that keys can map to multiple values.

module Query : sig ... end

Queries and query codecs.

type headers

The type for HTTP headers. Maps header names to string values such that for:

  • Single valued headers, the value is the string.
  • Multi-valued headers, the values are comma ',' separated as per specification. Use Headers.values_of_string on the string.
  • set_cookie header, must be treated specially since it can be repeated but does not follow the syntax of multi-valued headers. The values are stored in the string separated by '\x00' values. Use Headers.add_set_cookie and Headers.values_of_set_cookie_value to handle the field. On Headers.encode this results in separate set-cookie headers.
module Headers : sig ... end

HTTP headers and values.

Cookies.

Etags and ranges

module Etag : sig ... end

Entity tags.

module Range : sig ... end

Range requests.

Standard header names

val accept : name
val accept_charset : name
val accept_encoding : name
val accept_language : name
val accept_ranges : name
val age : name
val allow : name
val authorization : name
val cache_control : name
val connection : name
val content_encoding : name
val content_language : name
val content_length : name
val content_location : name
val content_range : name
val content_type : name
val date : name
val etag : name
val expect : name
val expires : name
val from : name
val host : name
val if_match : name
val if_modified_since : name
val if_none_match : name
val if_range : name
val if_unmodified_since : name
val last_modified : name
val location : name
val max_forwards : name
val pragma : name
val proxy_authenticate : name
val proxy_authorization : name
val range : name
val referer : name
val retry_after : name
val server : name
val te : name
val trailer : name
val transfer_encoding : name
val upgrade : name
val user_agent : name
val vary : name
val via : name
val warning : name
val www_authenticate : name

Status codes

type status = int

The type for HTTP status codes.

module Status : sig ... end

Statuses.

Informational 1xx

val continue_100 : status
val switching_protocols_101 : status

Sucessful 2xx

val ok_200 : status
val created_201 : status
val accepted_202 : status
val non_authoritative_information_203 : status
val no_content_204 : status
val reset_content_205 : status
val partial_content_206 : status

Redirection 3xx

val multiple_choices_300 : status
val moved_permanently_301 : status
val found_302 : status
val see_other_303 : status
val not_modified_304 : status
val use_proxy_305 : status
val temporary_redirect_307 : status

Client Error 4xx

val bad_request_400 : status
val unauthorized_401 : status
val payement_required_402 : status
val forbidden_403 : status
val not_found_404 : status
val method_not_allowed_405 : status
val not_acceptable_406 : status
val proxy_authentication_required_407 : status
val request_time_out_408 : status
val conflict_409 : status
val gone_410 : status
val length_required_411 : status
val precondition_failed_412 : status
val payload_too_large_413 : status
val uri_too_long_414 : status
val unsupported_media_type_415 : status
val range_not_satisfiable_416 : status
val expectation_failed_417 : status
val i'm_a_teapot_418 : status
val upgrade_required_426 : status

Server Error 5xx

val server_error_500 : status
val not_implemented_501 : status
val bad_gateway_502 : status
val service_unavailable_503 : status
val gateway_time_out_504 : status
val http_version_not_supported_505 : status

MIME types

type mime_type = string

The type for MIME types.

module Mime_type : sig ... end

MIME type constants and file extensions.

Low-level codecs

Low-level codecs

Warning. This API is unstable and subject to change between minor versions of the library.

module Private : sig ... end