package cohttp

  1. Overview
  2. Docs

Source file code.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
open! Sexplib0.Sexp_conv

type version = [ `HTTP_1_0 | `HTTP_1_1 | `Other of string ] [@@deriving sexp]

type meth =
  [ `GET
  | `POST
  | `HEAD
  | `DELETE
  | `PATCH
  | `PUT
  | `OPTIONS
  | `TRACE
  | `CONNECT
  | `Other of string ]
[@@deriving sexp]

type informational_status =
  [ `Continue | `Switching_protocols | `Processing | `Checkpoint ]
[@@deriving sexp]

type success_status =
  [ `OK
  | `Created
  | `Accepted
  | `Non_authoritative_information
  | `No_content
  | `Reset_content
  | `Partial_content
  | `Multi_status
  | `Already_reported
  | `Im_used ]
[@@deriving sexp]

type redirection_status =
  [ `Multiple_choices
  | `Moved_permanently
  | `Found
  | `See_other
  | `Not_modified
  | `Use_proxy
  | `Switch_proxy
  | `Temporary_redirect
  | `Permanent_redirect ]
[@@deriving sexp]

type client_error_status =
  [ `Bad_request
  | `Unauthorized
  | `Payment_required
  | `Forbidden
  | `Not_found
  | `Method_not_allowed
  | `Not_acceptable
  | `Proxy_authentication_required
  | `Request_timeout
  | `Conflict
  | `Gone
  | `Length_required
  | `Precondition_failed
  | `Request_entity_too_large
  | `Request_uri_too_long
  | `Unsupported_media_type
  | `Requested_range_not_satisfiable
  | `Expectation_failed
  | `I_m_a_teapot
  | `Enhance_your_calm
  | `Unprocessable_entity
  | `Locked
  | `Failed_dependency
  | `Upgrade_required
  | `Precondition_required
  | `Too_many_requests
  | `Request_header_fields_too_large
  | `No_response
  | `Retry_with
  | `Blocked_by_windows_parental_controls
  | `Wrong_exchange_server
  | `Client_closed_request ]
[@@deriving sexp]

type server_error_status =
  [ `Internal_server_error
  | `Not_implemented
  | `Bad_gateway
  | `Service_unavailable
  | `Gateway_timeout
  | `Http_version_not_supported
  | `Variant_also_negotiates
  | `Insufficient_storage
  | `Loop_detected
  | `Bandwidth_limit_exceeded
  | `Not_extended
  | `Network_authentication_required
  | `Network_read_timeout_error
  | `Network_connect_timeout_error ]
[@@deriving sexp]

type status =
  [ informational_status
  | success_status
  | redirection_status
  | client_error_status
  | server_error_status ]
[@@deriving sexp]

type status_code = [ `Code of int | status ] [@@deriving sexp]

let string_of_version = Http.Version.to_string
let version_of_string = Http.Version.of_string

let compare_version a b =
  String.compare (string_of_version a) (string_of_version b)

let string_of_method = Http.Method.to_string
let method_of_string = Http.Method.of_string

let compare_method a b =
  String.compare (string_of_method a) (string_of_method b)

let status_of_code = Http.Status.of_int
let code_of_status = Http.Status.to_int
let string_of_status = Http.Status.to_string
let reason_phrase_of_code = Http.Status.reason_phrase_of_code

let is_informational code =
  match status_of_code code with #informational_status -> true | _ -> false

let is_success code =
  match status_of_code code with #success_status -> true | _ -> false

let is_redirection code =
  match status_of_code code with #redirection_status -> true | _ -> false

let is_client_error code =
  match status_of_code code with #client_error_status -> true | _ -> false

let is_server_error code =
  match status_of_code code with #server_error_status -> true | _ -> false

let is_error code = is_client_error code || is_server_error code
OCaml

Innovation. Community. Security.