My agentic slop goes here. Not intended for anyone else!
at main 7.6 kB view raw
1(** HTTP status codes following RFC 7231 and extensions *) 2 3(** Log source for status code operations *) 4val src : Logs.Src.t 5 6(** {1 Status Categories} *) 7 8type informational = [ 9 | `Continue (** 100 - Client should continue with request *) 10 | `Switching_protocols (** 101 - Server is switching protocols *) 11 | `Processing (** 102 - Server has received and is processing the request *) 12 | `Early_hints (** 103 - Used to return some response headers before final HTTP message *) 13] 14(** 1xx Informational responses *) 15 16type success = [ 17 | `OK (** 200 - Standard response for successful HTTP requests *) 18 | `Created (** 201 - Request has been fulfilled; new resource created *) 19 | `Accepted (** 202 - Request accepted, processing pending *) 20 | `Non_authoritative_information (** 203 - Request processed, information may be from another source *) 21 | `No_content (** 204 - Request processed, no content returned *) 22 | `Reset_content (** 205 - Request processed, no content returned, reset document view *) 23 | `Partial_content (** 206 - Partial resource return due to request header *) 24 | `Multi_status (** 207 - XML, can contain multiple separate responses *) 25 | `Already_reported (** 208 - Results previously returned *) 26 | `Im_used (** 226 - Request fulfilled, response is instance-manipulations *) 27] 28(** 2xx Success responses *) 29 30type redirection = [ 31 | `Multiple_choices (** 300 - Multiple options for the resource delivered *) 32 | `Moved_permanently (** 301 - This and all future requests directed to the given URI *) 33 | `Found (** 302 - Temporary response to request found via alternative URI *) 34 | `See_other (** 303 - Response to request found via alternative URI *) 35 | `Not_modified (** 304 - Resource has not been modified since last requested *) 36 | `Use_proxy (** 305 - Content located elsewhere, retrieve from there (deprecated) *) 37 | `Temporary_redirect (** 307 - Connect again to different URI as provided *) 38 | `Permanent_redirect (** 308 - Connect again to a different URI using the same method *) 39] 40(** 3xx Redirection messages *) 41 42type client_error = [ 43 | `Bad_request (** 400 - Request cannot be fulfilled due to bad syntax *) 44 | `Unauthorized (** 401 - Authentication is possible but has failed *) 45 | `Payment_required (** 402 - Payment required, reserved for future use *) 46 | `Forbidden (** 403 - Server refuses to respond to request *) 47 | `Not_found (** 404 - Requested resource could not be found *) 48 | `Method_not_allowed (** 405 - Request method not supported by that resource *) 49 | `Not_acceptable (** 406 - Content not acceptable according to the Accept headers *) 50 | `Proxy_authentication_required (** 407 - Client must first authenticate itself with the proxy *) 51 | `Request_timeout (** 408 - Server timed out waiting for the request *) 52 | `Conflict (** 409 - Request could not be processed because of conflict *) 53 | `Gone (** 410 - Resource is no longer available and will not be available again *) 54 | `Length_required (** 411 - Request did not specify the length of its content *) 55 | `Precondition_failed (** 412 - Server does not meet request preconditions *) 56 | `Payload_too_large (** 413 - Request is larger than the server is willing or able to process *) 57 | `Uri_too_long (** 414 - URI provided was too long for the server to process *) 58 | `Unsupported_media_type (** 415 - Server does not support media type *) 59 | `Range_not_satisfiable (** 416 - Client has asked for unprovidable portion of the file *) 60 | `Expectation_failed (** 417 - Server cannot meet requirements of Expect request-header field *) 61 | `I_m_a_teapot (** 418 - I'm a teapot (RFC 2324) *) 62 | `Misdirected_request (** 421 - Request was directed at a server that is not able to produce a response *) 63 | `Unprocessable_entity (** 422 - Request unable to be followed due to semantic errors *) 64 | `Locked (** 423 - Resource that is being accessed is locked *) 65 | `Failed_dependency (** 424 - Request failed due to failure of a previous request *) 66 | `Too_early (** 425 - Server is unwilling to risk processing a request that might be replayed *) 67 | `Upgrade_required (** 426 - Client should switch to a different protocol *) 68 | `Precondition_required (** 428 - Origin server requires the request to be conditional *) 69 | `Too_many_requests (** 429 - User has sent too many requests in a given amount of time *) 70 | `Request_header_fields_too_large (** 431 - Server is unwilling to process the request *) 71 | `Unavailable_for_legal_reasons (** 451 - Resource unavailable for legal reasons *) 72] 73(** 4xx Client error responses *) 74 75type server_error = [ 76 | `Internal_server_error (** 500 - Generic error message *) 77 | `Not_implemented (** 501 - Server does not recognise method or lacks ability to fulfill *) 78 | `Bad_gateway (** 502 - Server received an invalid response from upstream server *) 79 | `Service_unavailable (** 503 - Server is currently unavailable *) 80 | `Gateway_timeout (** 504 - Gateway did not receive response from upstream server *) 81 | `Http_version_not_supported (** 505 - Server does not support the HTTP protocol version *) 82 | `Variant_also_negotiates (** 506 - Content negotiation for the request results in a circular reference *) 83 | `Insufficient_storage (** 507 - Server is unable to store the representation *) 84 | `Loop_detected (** 508 - Server detected an infinite loop while processing the request *) 85 | `Not_extended (** 510 - Further extensions to the request are required *) 86 | `Network_authentication_required (** 511 - Client needs to authenticate to gain network access *) 87] 88(** 5xx Server error responses *) 89 90type standard = [ 91 | informational 92 | success 93 | redirection 94 | client_error 95 | server_error 96] 97(** All standard HTTP status codes *) 98 99type t = [ 100 | `Code of int (** Any status code as an integer *) 101 | standard 102] 103(** HTTP status type *) 104 105(** {1 Conversion Functions} *) 106 107val to_int : t -> int 108(** Convert status to its integer code *) 109 110val of_int : int -> t 111(** Convert an integer to a status *) 112 113val to_string : t -> string 114(** Get the string representation of a status code (e.g., "200", "404") *) 115 116val reason_phrase : t -> string 117(** Get the standard reason phrase for a status code (e.g., "OK", "Not Found") *) 118 119(** {1 Classification Functions} *) 120 121val is_informational : t -> bool 122(** Check if status code is informational (1xx) *) 123 124val is_success : t -> bool 125(** Check if status code indicates success (2xx) *) 126 127val is_redirection : t -> bool 128(** Check if status code indicates redirection (3xx) *) 129 130val is_client_error : t -> bool 131(** Check if status code indicates client error (4xx) *) 132 133val is_server_error : t -> bool 134(** Check if status code indicates server error (5xx) *) 135 136val is_error : t -> bool 137(** Check if status code indicates any error (4xx or 5xx) *) 138 139(** {1 Retry Policy} *) 140 141val is_retryable : t -> bool 142(** Check if a status code suggests the request could be retried. 143 Returns true for: 144 - 408 Request Timeout 145 - 429 Too Many Requests 146 - 502 Bad Gateway 147 - 503 Service Unavailable 148 - 504 Gateway Timeout 149 - Any 5xx errors *) 150 151val should_retry_on_different_host : t -> bool 152(** Check if a status code suggests retrying on a different host might help. 153 Returns true for: 154 - 502 Bad Gateway 155 - 503 Service Unavailable 156 - 504 Gateway Timeout *) 157 158(** {1 Pretty Printing} *) 159 160val pp : Format.formatter -> t -> unit 161(** Pretty printer for status codes *) 162 163val pp_hum : Format.formatter -> t -> unit 164(** Human-readable pretty printer that includes both code and reason phrase *)