Source file http_status.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
(** Non-comprehensive list of HTTP response status codes and strings from
    http://en.wikipedia.org/wiki/List_of_HTTP_status_codes *)
type t =
  [ `Ok
  | `Created
  | `Accepted
  | `Non_authoritative_information
  | `No_content
  | `Reset_content
  | `Partial_content
  | `Multiple_choices
  | `Moved_permanently
  | `Found
  | `See_other
  | `Not_modified
  | `Temporary_redirect
  | `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
  | `Internal_server_error
  | `Not_implemented
  | `Bad_gateway
  | `Service_unavailable
  | `Gateway_timeout
  | `Http_version_not_supported
  | `Custom_code of int * string ]

let to_pair = function
  | `Ok ->
      (200, "OK")
  | `Created ->
      (201, "Created")
  | `Accepted ->
      (202, "Accepted")
  | `Non_authoritative_information ->
      (203, "Non-Authoritative Information")
  | `No_content ->
      (204, "No Content")
  | `Reset_content ->
      (205, "Reset Content")
  | `Partial_content ->
      (206, "Partial Content")
  | `Multiple_choices ->
      (300, "Multiple Choices")
  | `Moved_permanently ->
      (301, "Moved Permanently")
  | `Found ->
      (302, "Found")
  | `See_other ->
      (303, "See Other")
  | `Not_modified ->
      (304, "Not Modified")
  | `Temporary_redirect ->
      (307, "Temporary Redirect")
  | `Bad_request ->
      (400, "Bad Request")
  | `Unauthorized ->
      (401, "Unauthorized")
  | `Payment_required ->
      (402, "Payment Required")
  | `Forbidden ->
      (403, "Forbidden")
  | `Not_found ->
      (404, "Not Found")
  | `Method_not_allowed ->
      (405, "Method Not Allowed")
  | `Not_acceptable ->
      (406, "Not Acceptable")
  | `Proxy_authentication_required ->
      (407, "Proxy Authentication Required")
  | `Request_timeout ->
      (408, "Request Timeout")
  | `Conflict ->
      (409, "Conflict")
  | `Gone ->
      (410, "Gone")
  | `Length_required ->
      (411, "Length Required")
  | `Precondition_failed ->
      (412, "Precondition Failed")
  | `Request_entity_too_large ->
      (413, "Request Entity Too Large")
  | `Request_uri_too_long ->
      (414, "Request URI Too Long")
  | `Unsupported_media_type ->
      (415, "Unsupported Media Type")
  | `Requested_range_not_satisfiable ->
      (416, "Request Range Not Satisfiable")
  | `Expectation_failed ->
      (417, "Expectation Failed")
  | `Internal_server_error ->
      (500, "Internal Server Error")
  | `Not_implemented ->
      (501, "Not Implemented")
  | `Bad_gateway ->
      (502, "Bad Gateway")
  | `Service_unavailable ->
      (503, "Service Unavailable")
  | `Gateway_timeout ->
      (504, "Gateway Timeout")
  | `Http_version_not_supported ->
      (505, "HTTP Version Not Supported")
  | `Custom_code (code, name) ->
      (code, name)

let values = to_pair

let to_int v = fst (to_pair v)

let to_string v = snd (to_pair v)

let of_pair (code, reason) =
  match code with
  | 200 ->
      `Ok
  | 201 ->
      `Created
  | 202 ->
      `Accepted
  | 203 ->
      `Non_authoritative_information
  | 204 ->
      `No_content
  | 205 ->
      `Reset_content
  | 206 ->
      `Partial_content
  | 300 ->
      `Multiple_choices
  | 301 ->
      `Moved_permanently
  | 302 ->
      `Found
  | 303 ->
      `See_other
  | 304 ->
      `Not_modified
  | 307 ->
      `Temporary_redirect
  | 400 ->
      `Bad_request
  | 401 ->
      `Unauthorized
  | 402 ->
      `Payment_required
  | 403 ->
      `Forbidden
  | 404 ->
      `Not_found
  | 405 ->
      `Method_not_allowed
  | 406 ->
      `Not_acceptable
  | 407 ->
      `Proxy_authentication_required
  | 408 ->
      `Request_timeout
  | 409 ->
      `Conflict
  | 410 ->
      `Gone
  | 411 ->
      `Length_required
  | 412 ->
      `Precondition_failed
  | 413 ->
      `Request_entity_too_large
  | 414 ->
      `Request_uri_too_long
  | 415 ->
      `Unsupported_media_type
  | 416 ->
      `Requested_range_not_satisfiable
  | 417 ->
      `Expectation_failed
  | 500 ->
      `Internal_server_error
  | 501 ->
      `Not_implemented
  | 502 ->
      `Bad_gateway
  | 503 ->
      `Service_unavailable
  | 504 ->
      `Gateway_timeout
  | 505 ->
      `Http_version_not_supported
  | code ->
      `Custom_code (code, reason)