Module Status

HTTP status codes per RFC 9110 Section 15

This module provides types and functions for working with HTTP response status codes. Status codes are three-digit integers that indicate the result of an HTTP request.

Status Code Classes

val src : Logs.Src.t

Log source for status code operations

Status Categories

type informational = [
  1. | `Continue
    (*

    100 - Client should continue with request

    *)
  2. | `Switching_protocols
    (*

    101 - Server is switching protocols

    *)
  3. | `Processing
    (*

    102 - Server has received and is processing the request

    *)
  4. | `Early_hints
    (*

    103 - Used to return some response headers before final HTTP message

    *)
]

1xx Informational responses

type success = [
  1. | `OK
    (*

    200 - Standard response for successful HTTP requests

    *)
  2. | `Created
    (*

    201 - Request has been fulfilled; new resource created

    *)
  3. | `Accepted
    (*

    202 - Request accepted, processing pending

    *)
  4. | `Non_authoritative_information
    (*

    203 - Request processed, information may be from another source

    *)
  5. | `No_content
    (*

    204 - Request processed, no content returned

    *)
  6. | `Reset_content
    (*

    205 - Request processed, no content returned, reset document view

    *)
  7. | `Partial_content
    (*

    206 - Partial resource return due to request header

    *)
  8. | `Multi_status
    (*

    207 - XML, can contain multiple separate responses

    *)
  9. | `Already_reported
    (*

    208 - Results previously returned

    *)
  10. | `Im_used
    (*

    226 - Request fulfilled, response is instance-manipulations

    *)
]

2xx Success responses

type redirection = [
  1. | `Multiple_choices
    (*

    300 - Multiple options for the resource delivered

    *)
  2. | `Moved_permanently
    (*

    301 - This and all future requests directed to the given URI

    *)
  3. | `Found
    (*

    302 - Temporary response to request found via alternative URI

    *)
  4. | `See_other
    (*

    303 - Response to request found via alternative URI

    *)
  5. | `Not_modified
    (*

    304 - Resource has not been modified since last requested

    *)
  6. | `Use_proxy
    (*

    305 - Content located elsewhere, retrieve from there (deprecated)

    *)
  7. | `Temporary_redirect
    (*

    307 - Connect again to different URI as provided

    *)
  8. | `Permanent_redirect
    (*

    308 - Connect again to a different URI using the same method

    *)
]

3xx Redirection messages

type client_error = [
  1. | `Bad_request
    (*

    400 - Request cannot be fulfilled due to bad syntax

    *)
  2. | `Unauthorized
    (*

    401 - Authentication is possible but has failed

    *)
  3. | `Payment_required
    (*

    402 - Payment required, reserved for future use

    *)
  4. | `Forbidden
    (*

    403 - Server refuses to respond to request

    *)
  5. | `Not_found
    (*

    404 - Requested resource could not be found

    *)
  6. | `Method_not_allowed
    (*

    405 - Request method not supported by that resource

    *)
  7. | `Not_acceptable
    (*

    406 - Content not acceptable according to the Accept headers

    *)
  8. | `Proxy_authentication_required
    (*

    407 - Client must first authenticate itself with the proxy

    *)
  9. | `Request_timeout
    (*

    408 - Server timed out waiting for the request

    *)
  10. | `Conflict
    (*

    409 - Request could not be processed because of conflict

    *)
  11. | `Gone
    (*

    410 - Resource is no longer available and will not be available again

    *)
  12. | `Length_required
    (*

    411 - Request did not specify the length of its content

    *)
  13. | `Precondition_failed
    (*

    412 - Server does not meet request preconditions

    *)
  14. | `Payload_too_large
    (*

    413 - Request is larger than the server is willing or able to process

    *)
  15. | `Uri_too_long
    (*

    414 - URI provided was too long for the server to process

    *)
  16. | `Unsupported_media_type
    (*

    415 - Server does not support media type

    *)
  17. | `Range_not_satisfiable
    (*

    416 - Client has asked for unprovidable portion of the file

    *)
  18. | `Expectation_failed
    (*

    417 - Server cannot meet requirements of Expect request-header field

    *)
  19. | `I_m_a_teapot
    (*

    418 - I'm a teapot (RFC 2324)

    *)
  20. | `Misdirected_request
    (*

    421 - Request was directed at a server that is not able to produce a response

    *)
  21. | `Unprocessable_entity
    (*

    422 - Request unable to be followed due to semantic errors

    *)
  22. | `Locked
    (*

    423 - Resource that is being accessed is locked

    *)
  23. | `Failed_dependency
    (*

    424 - Request failed due to failure of a previous request

    *)
  24. | `Too_early
    (*

    425 - Server is unwilling to risk processing a request that might be replayed

    *)
  25. | `Upgrade_required
    (*

    426 - Client should switch to a different protocol

    *)
  26. | `Precondition_required
    (*

    428 - Origin server requires the request to be conditional

    *)
  27. | `Too_many_requests
    (*

    429 - User has sent too many requests in a given amount of time

    *)
  28. | `Request_header_fields_too_large
    (*

    431 - Server is unwilling to process the request

    *)
]

4xx Client error responses

type server_error = [
  1. | `Internal_server_error
    (*

    500 - Generic error message

    *)
  2. | `Not_implemented
    (*

    501 - Server does not recognise method or lacks ability to fulfill

    *)
  3. | `Bad_gateway
    (*

    502 - Server received an invalid response from upstream server

    *)
  4. | `Service_unavailable
    (*

    503 - Server is currently unavailable

    *)
  5. | `Gateway_timeout
    (*

    504 - Gateway did not receive response from upstream server

    *)
  6. | `Http_version_not_supported
    (*

    505 - Server does not support the HTTP protocol version

    *)
  7. | `Variant_also_negotiates
    (*

    506 - Content negotiation for the request results in a circular reference

    *)
  8. | `Insufficient_storage
    (*

    507 - Server is unable to store the representation

    *)
  9. | `Loop_detected
    (*

    508 - Server detected an infinite loop while processing the request

    *)
  10. | `Not_extended
    (*

    510 - Further extensions to the request are required

    *)
  11. | `Network_authentication_required
    (*

    511 - Client needs to authenticate to gain network access

    *)
]

5xx Server error responses

All standard HTTP status codes

type t = [
  1. | `Code of int
    (*

    Any status code as an integer

    *)
  2. | standard
]

HTTP status type

Conversion Functions

val to_int : t -> int

Convert status to its integer code

val of_int : int -> t

Convert an integer to a status

val to_string : t -> string

Get the string representation of a status code (e.g., "200", "404")

val reason_phrase : t -> string

Get the standard reason phrase for a status code (e.g., "OK", "Not Found")

Classification Functions

val is_informational : t -> bool

Check if status code is informational (1xx)

val is_success : t -> bool

Check if status code indicates success (2xx)

val is_redirection : t -> bool

Check if status code indicates redirection (3xx)

val is_client_error : t -> bool

Check if status code indicates client error (4xx)

val is_server_error : t -> bool

Check if status code indicates server error (5xx)

val is_error : t -> bool

Check if status code indicates any error (4xx or 5xx)

Retry Policy

val is_retryable : t -> bool

Check if a status code suggests the request could be retried. Returns true for:

  • 408 Request Timeout
  • 429 Too Many Requests
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout
  • Any 5xx errors
val should_retry_on_different_host : t -> bool

Check if a status code suggests retrying on a different host might help. Returns true for:

  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout

Pretty Printing

val pp : Format.formatter -> t -> unit

Pretty printer for status codes

val pp_hum : Format.formatter -> t -> unit

Human-readable pretty printer that includes both code and reason phrase