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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
(* Auto-Generated by 'ocaml generate.ml' *)
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
  | `Resume_incomplete
  ] [@@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: version -> string = function
  | `HTTP_1_0 -> "HTTP/1.0"
  | `HTTP_1_1 -> "HTTP/1.1"
  | `Other s -> s

let version_of_string: string -> version = function
  | "HTTP/1.0" -> `HTTP_1_0
  | "HTTP/1.1" -> `HTTP_1_1
  | s -> `Other s

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


let string_of_method: meth -> string = function
  | `GET -> "GET"
  | `POST -> "POST"
  | `HEAD -> "HEAD"
  | `DELETE -> "DELETE"
  | `PATCH -> "PATCH"
  | `PUT -> "PUT"
  | `OPTIONS -> "OPTIONS"
  | `TRACE -> "TRACE"
  | `CONNECT -> "CONNECT"
  | `Other s -> s

let method_of_string: string -> meth = function
  | "GET" -> `GET
  | "POST" -> `POST
  | "HEAD" -> `HEAD
  | "DELETE" -> `DELETE
  | "PATCH" -> `PATCH
  | "PUT" -> `PUT
  | "OPTIONS" -> `OPTIONS
  | "TRACE" -> `TRACE
  | "CONNECT" -> `CONNECT
  | s -> `Other s

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


let status_of_code: int -> status_code = function
  | 100 -> `Continue
  | 101 -> `Switching_protocols
  | 102 -> `Processing
  | 103 -> `Checkpoint
  | 200 -> `OK
  | 201 -> `Created
  | 202 -> `Accepted
  | 203 -> `Non_authoritative_information
  | 204 -> `No_content
  | 205 -> `Reset_content
  | 206 -> `Partial_content
  | 207 -> `Multi_status
  | 208 -> `Already_reported
  | 226 -> `Im_used
  | 300 -> `Multiple_choices
  | 301 -> `Moved_permanently
  | 302 -> `Found
  | 303 -> `See_other
  | 304 -> `Not_modified
  | 305 -> `Use_proxy
  | 306 -> `Switch_proxy
  | 307 -> `Temporary_redirect
  | 308 -> `Resume_incomplete
  | 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
  | 418 -> `I_m_a_teapot
  | 420 -> `Enhance_your_calm
  | 422 -> `Unprocessable_entity
  | 423 -> `Locked
  | 424 -> `Failed_dependency
  | 426 -> `Upgrade_required
  | 428 -> `Precondition_required
  | 429 -> `Too_many_requests
  | 431 -> `Request_header_fields_too_large
  | 444 -> `No_response
  | 449 -> `Retry_with
  | 450 -> `Blocked_by_windows_parental_controls
  | 451 -> `Wrong_exchange_server
  | 499 -> `Client_closed_request
  | 500 -> `Internal_server_error
  | 501 -> `Not_implemented
  | 502 -> `Bad_gateway
  | 503 -> `Service_unavailable
  | 504 -> `Gateway_timeout
  | 505 -> `Http_version_not_supported
  | 506 -> `Variant_also_negotiates
  | 507 -> `Insufficient_storage
  | 508 -> `Loop_detected
  | 509 -> `Bandwidth_limit_exceeded
  | 510 -> `Not_extended
  | 511 -> `Network_authentication_required
  | 598 -> `Network_read_timeout_error
  | 599 -> `Network_connect_timeout_error
  | cod -> `Code cod

let code_of_status: status_code -> int = function
  | `Continue -> 100
  | `Switching_protocols -> 101
  | `Processing -> 102
  | `Checkpoint -> 103
  | `OK -> 200
  | `Created -> 201
  | `Accepted -> 202
  | `Non_authoritative_information -> 203
  | `No_content -> 204
  | `Reset_content -> 205
  | `Partial_content -> 206
  | `Multi_status -> 207
  | `Already_reported -> 208
  | `Im_used -> 226
  | `Multiple_choices -> 300
  | `Moved_permanently -> 301
  | `Found -> 302
  | `See_other -> 303
  | `Not_modified -> 304
  | `Use_proxy -> 305
  | `Switch_proxy -> 306
  | `Temporary_redirect -> 307
  | `Resume_incomplete -> 308
  | `Bad_request -> 400
  | `Unauthorized -> 401
  | `Payment_required -> 402
  | `Forbidden -> 403
  | `Not_found -> 404
  | `Method_not_allowed -> 405
  | `Not_acceptable -> 406
  | `Proxy_authentication_required -> 407
  | `Request_timeout -> 408
  | `Conflict -> 409
  | `Gone -> 410
  | `Length_required -> 411
  | `Precondition_failed -> 412
  | `Request_entity_too_large -> 413
  | `Request_uri_too_long -> 414
  | `Unsupported_media_type -> 415
  | `Requested_range_not_satisfiable -> 416
  | `Expectation_failed -> 417
  | `I_m_a_teapot -> 418
  | `Enhance_your_calm -> 420
  | `Unprocessable_entity -> 422
  | `Locked -> 423
  | `Failed_dependency -> 424
  | `Upgrade_required -> 426
  | `Precondition_required -> 428
  | `Too_many_requests -> 429
  | `Request_header_fields_too_large -> 431
  | `No_response -> 444
  | `Retry_with -> 449
  | `Blocked_by_windows_parental_controls -> 450
  | `Wrong_exchange_server -> 451
  | `Client_closed_request -> 499
  | `Internal_server_error -> 500
  | `Not_implemented -> 501
  | `Bad_gateway -> 502
  | `Service_unavailable -> 503
  | `Gateway_timeout -> 504
  | `Http_version_not_supported -> 505
  | `Variant_also_negotiates -> 506
  | `Insufficient_storage -> 507
  | `Loop_detected -> 508
  | `Bandwidth_limit_exceeded -> 509
  | `Not_extended -> 510
  | `Network_authentication_required -> 511
  | `Network_read_timeout_error -> 598
  | `Network_connect_timeout_error -> 599
  | `Code cod -> cod

let string_of_status: status_code -> string = function
  | `Continue -> "100 Continue"
  | `Switching_protocols -> "101 Switching Protocols"
  | `Processing -> "102 Processing (WebDAV) (RFC 2518)"
  | `Checkpoint -> "103 Checkpoint"
  | `OK -> "200 OK"
  | `Created -> "201 Created"
  | `Accepted -> "202 Accepted"
  | `Non_authoritative_information -> "203 Non-Authoritative Information (since HTTP/1.1)"
  | `No_content -> "204 No Content"
  | `Reset_content -> "205 Reset Content"
  | `Partial_content -> "206 Partial Content"
  | `Multi_status -> "207 Multi-Status (WebDAV) (RFC 4918)"
  | `Already_reported -> "208 Already Reported (WebDAV) (RFC 5842)"
  | `Im_used -> "226 IM Used (RFC 3229)"
  | `Multiple_choices -> "300 Multiple Choices"
  | `Moved_permanently -> "301 Moved Permanently"
  | `Found -> "302 Found"
  | `See_other -> "303 See Other"
  | `Not_modified -> "304 Not Modified"
  | `Use_proxy -> "305 Use Proxy (since HTTP/1.1)"
  | `Switch_proxy -> "306 Switch Proxy"
  | `Temporary_redirect -> "307 Temporary Redirect (since HTTP/1.1)"
  | `Resume_incomplete -> "308 Resume Incomplete"
  | `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 Requested Range Not Satisfiable"
  | `Expectation_failed -> "417 Expectation Failed"
  | `I_m_a_teapot -> "418 I'm a teapot (RFC 2324)"
  | `Enhance_your_calm -> "420 Enhance Your Calm"
  | `Unprocessable_entity -> "422 Unprocessable Entity (WebDAV) (RFC 4918)"
  | `Locked -> "423 Locked (WebDAV) (RFC 4918)"
  | `Failed_dependency -> "424 Failed Dependency (WebDAV) (RFC 4918)"
  | `Upgrade_required -> "426 Upgrade Required (RFC 2817)"
  | `Precondition_required -> "428 Precondition Required"
  | `Too_many_requests -> "429 Too Many Requests"
  | `Request_header_fields_too_large -> "431 Request Header Fields Too Large"
  | `No_response -> "444 No Response"
  | `Retry_with -> "449 Retry With"
  | `Blocked_by_windows_parental_controls -> "450 Blocked by Windows Parental Controls"
  | `Wrong_exchange_server -> "451 Wrong Exchange server"
  | `Client_closed_request -> "499 Client Closed Request"
  | `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"
  | `Variant_also_negotiates -> "506 Variant Also Negotiates (RFC 2295)"
  | `Insufficient_storage -> "507 Insufficient Storage (WebDAV) (RFC 4918)"
  | `Loop_detected -> "508 Loop Detected (WebDAV) (RFC 5842)"
  | `Bandwidth_limit_exceeded -> "509 Bandwidth Limit Exceeded (Apache bw/limited extension)"
  | `Not_extended -> "510 Not Extended (RFC 2774)"
  | `Network_authentication_required -> "511 Network Authentication Required"
  | `Network_read_timeout_error -> "598 Network read timeout error"
  | `Network_connect_timeout_error -> "599 Network connect timeout error"
  | `Code cod -> string_of_int cod

let reason_phrase_of_code: int -> string = function
  | 100 -> "Continue"
  | 101 -> "Switching Protocols"
  | 102 -> "Processing (WebDAV) (RFC 2518)"
  | 103 -> "Checkpoint"
  | 200 -> "OK"
  | 201 -> "Created"
  | 202 -> "Accepted"
  | 203 -> "Non-Authoritative Information (since HTTP/1.1)"
  | 204 -> "No Content"
  | 205 -> "Reset Content"
  | 206 -> "Partial Content"
  | 207 -> "Multi-Status (WebDAV) (RFC 4918)"
  | 208 -> "Already Reported (WebDAV) (RFC 5842)"
  | 226 -> "IM Used (RFC 3229)"
  | 300 -> "Multiple Choices"
  | 301 -> "Moved Permanently"
  | 302 -> "Found"
  | 303 -> "See Other"
  | 304 -> "Not Modified"
  | 305 -> "Use Proxy (since HTTP/1.1)"
  | 306 -> "Switch Proxy"
  | 307 -> "Temporary Redirect (since HTTP/1.1)"
  | 308 -> "Resume Incomplete"
  | 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"
  | 418 -> "I'm a teapot (RFC 2324)"
  | 420 -> "Enhance Your Calm"
  | 422 -> "Unprocessable Entity (WebDAV) (RFC 4918)"
  | 423 -> "Locked (WebDAV) (RFC 4918)"
  | 424 -> "Failed Dependency (WebDAV) (RFC 4918)"
  | 426 -> "Upgrade Required (RFC 2817)"
  | 428 -> "Precondition Required"
  | 429 -> "Too Many Requests"
  | 431 -> "Request Header Fields Too Large"
  | 444 -> "No Response"
  | 449 -> "Retry With"
  | 450 -> "Blocked by Windows Parental Controls"
  | 451 -> "Wrong Exchange server"
  | 499 -> "Client Closed Request"
  | 500 -> "Internal Server Error"
  | 501 -> "Not Implemented"
  | 502 -> "Bad Gateway"
  | 503 -> "Service Unavailable"
  | 504 -> "Gateway Timeout"
  | 505 -> "HTTP Version Not Supported"
  | 506 -> "Variant Also Negotiates (RFC 2295)"
  | 507 -> "Insufficient Storage (WebDAV) (RFC 4918)"
  | 508 -> "Loop Detected (WebDAV) (RFC 5842)"
  | 509 -> "Bandwidth Limit Exceeded (Apache bw/limited extension)"
  | 510 -> "Not Extended (RFC 2774)"
  | 511 -> "Network Authentication Required"
  | 598 -> "Network read timeout error"
  | 599 -> "Network connect timeout error"
  | cod -> string_of_int cod

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.