package h2

  1. Overview
  2. Docs

Response Status Codes

The status-code element is a three-digit integer code giving the result of the attempt to understand and satisfy the request.

See RFC7231§6 for more details.

This module is a strict superset of Httpaf.Status. Even though the HTTP/2 specification removes support for the Switching_protocols status code, h2 keeps it for the sake of higher level interaction between OCaml libraries that support both HTTP/1 and HTTP/2.

See RFC7540§8.1.1 for more details.

include module type of Httpaf.Status with type client_error := Httpaf.Status.client_error and type standard := Httpaf.Status.standard and type t := Httpaf.Status.t
type informational = [
  1. | `Continue
  2. | `Switching_protocols
]
type successful = [
  1. | `Accepted
  2. | `Created
  3. | `No_content
  4. | `Non_authoritative_information
  5. | `OK
  6. | `Partial_content
  7. | `Reset_content
]
type redirection = [
  1. | `Found
  2. | `Moved_permanently
  3. | `Multiple_choices
  4. | `Not_modified
  5. | `See_other
  6. | `Temporary_redirect
  7. | `Use_proxy
]
type server_error = [
  1. | `Bad_gateway
  2. | `Gateway_timeout
  3. | `Http_version_not_supported
  4. | `Internal_server_error
  5. | `Not_implemented
  6. | `Service_unavailable
]
type client_error = [
  1. | Httpaf.Status.client_error
  2. | `Misdirected_request
]

The 4xx (Client Error) class of status code indicates that the client seems to have erred.

See RFC7231§6.5 for more details.

In addition to http/af, this type also includes the 421 (Misdirected Request) tag. See RFC7540§9.1.2 for more details.

type standard = [
  1. | Httpaf.Status.standard
  2. | client_error
]

The status codes defined in the HTTP/1.1 RFCs, excluding the Switching Protocols status and including the Misdirected Request as per the HTTP/2 RFC.

See RFC7540§8.1.1 and RFC7540§9.1.2 for more details.

type t = [
  1. | standard
  2. | `Code of int
]

The standard codes along with support for custom codes.

val default_reason_phrase : standard -> string

default_reason_phrase standard is the example reason phrase provided by RFC7231 for the standard status code. The RFC allows servers to use reason phrases besides these in responses.

val to_code : t -> int

to_code t is the integer representation of t.

val of_code : int -> t

of_code i is the t representation of i. of_code raises Failure if i is not a positive three-digit number.

val unsafe_of_code : int -> t

unsafe_of_code i is equivalent to of_code i, except it accepts any positive code, regardless of the number of digits it has. On negative codes, it will still raise Failure.

val is_informational : t -> bool

is_informational t is true iff t belongs to the Informational class of status codes.

val is_successful : t -> bool

is_successful t is true iff t belongs to the Successful class of status codes.

val is_redirection : t -> bool

is_redirection t is true iff t belongs to the Redirection class of status codes.

val is_client_error : t -> bool

is_client_error t is true iff t belongs to the Client Error class of status codes.

val is_server_error : t -> bool

is_server_error t is true iff t belongs to the Server Error class of status codes.

val is_error : t -> bool

is_server_error t is true iff t belongs to the Client Error or Server Error class of status codes.

val to_string : t -> string
val of_string : string -> t
val pp_hum : Stdlib.Format.formatter -> t -> unit
OCaml

Innovation. Community. Security.