Module Webs.HTTP

module HTTP: sig .. end
HTTP types, fragment codecs and constants.

HTTP provides types, helper functions and constants for HTTP versions, methods, headers, status codes and paths.

References.




Versions


type version = int * int 
The type for representing HTTP-version fields. Both integers must be in the interval [0;9].
val decode_version : string -> version option
decode_version s decodes an HTTP-version field from s.
val encode_version : version -> string
encode_version v encodes an HTTP-version field value for v.
Raises Invalid_argument if v's integer are not in the interval [0;9]
val pp_version : Format.formatter -> version -> unit
pp_version ppf v prints v an unspecified representation of v on ppf.
Raises Invalid_argument if v's integer are not in the interval [0;9]

Methods


type meth = [ `CONNECT
| `DELETE
| `GET
| `HEAD
| `OPTIONS
| `Other of string
| `PATCH
| `POST
| `PUT
| `TRACE ]
The type for HTTP request methods.
val decode_meth : string -> meth option
decode_meth s decodes a method for s.
val encode_meth : meth -> string
encode_meth m encodes a method for v.
Raises Invalid_argument if m is `Other t and t is not a token.
val pp_meth : Format.formatter -> meth -> unit
pp_method ppf m prints and unspecified representation of m on ppf.
Raises Invalid_argument if m is `Other t and t is not a token.

Headers


type headers 
The type for header maps.

A header map represents a list of HTTP headers. It maps header field names to their value.

val pp_headers : Format.formatter -> headers -> unit
pp_headers ppf hs prints an unspecified representation of hs on ppf.
module H: sig .. end
Headers.

Status codes


type status = int 
The type for HTTP status codes.
val status_reason_phrase : status -> string
status_reason_phrase s is s's reason phrase.
val pp_status : Format.formatter -> status -> unit
pp_status ppf s prints an unspecified representation of s on ppf.

Informational 1xx


val s100_continue : status
100
val s101_switching_protocols : status
101

Sucessful 2xx


val s200_ok : status
200
val s201_created : status
201
val s202_accepted : status
202
val s203_non_authoritative_information : status
203
val s204_no_content : status
204
val s205_reset_content : status
205
val s206_partial_content : status
206

Redirection 3xx


val s300_multiple_choices : status
300
val s301_moved_permanently : status
301
val s302_found : status
302
val s303_see_other : status
303
val s304_not_modified : status
304
val s305_use_proxy : status
305
val s307_temporary_redirect : status
307

Client Error 4xx


val s400_bad_request : status
400
val s401_unauthorized : status
401
val s402_payement_required : status
402
val s403_forbidden : status
403
val s404_not_found : status
404
val s405_not_allowed : status
405
val s406_not_acceptable : status
406
val s407_proxy_authentication_required : status
407
val s408_request_time_out : status
408
val s409_conflict : status
409
val s410_gone : status
410
val s411_length_required : status
411
val s412_precondition_failed : status
412
val s413_payload_too_large : status
413
val s414_uri_too_long : status
414
val s415_unsupported_media_type : status
415
val s416_range_not_satisfiable : status
416
val s417_expectation_failed : status
417
val s426_upgrade_required : status
436

Server Error 5xx


val s500_server_error : status
500
val s501_not_implemented : status
501
val s502_bad_gateway : status
502
val s503_service_unavailable : status
503
val s504_gateway_time_out : status
504
val s505_http_version_not_supported : status
505

Paths


type path = string list 
The type for HTTP absolute-paths represented by its non-empty list of URI segments. Note that URI segments can be empty; in particular the absolute path "/" is the list with a single empty segment and is thus represented by the list [""].
val decode_path : string -> path option
decode_path s decodes an absolute-path to its percent-decoded list of segments. By definition of absolute-path the list of segments is never empty, "/" is represented by the singelton empty segment [""].

Here are a few examples:


val encode_path : path -> string
encode_path p encodes an absolute-path for p as follows:
  1. In each segment percent-encode any byte that is not unreserved, sub-delims, ':' or '@' and hence producing a valid URI segment
  2. Prepends each segment with a '/'
  3. Concatenate the result.

Raises Invalid_argument if p is the empty list.

Here are a few examples:


val pp_path : ?human:bool -> unit -> Format.formatter -> path -> unit
pp_path human () ppf p prints an unspecified representation of p on ppf if human is true (defaults to false) the is prettified for human presentation rather than debugging.

Miscenalleous codecs


val decode_digits : string -> int option
decode_digits s decodes a sequence of DIGITs to a positive integer. Returns None on overflows
val encode_digits : int -> string
encode_digits i encodes i as a sequence of DIGITs.
Raises Invalid_argumnet if i is negative.
val is_token : string -> bool
is_token s is true iff s in an HTTP a token.