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
open Core
module T = struct
type t =
[
`GET
| `HEAD
| `POST
| `PUT
| `DELETE
| `CONNECT
| `OPTIONS
| `TRACE
|
`PATCH
]
[@@deriving sexp, compare, hash, enumerate, quickcheck]
end
include T
include Comparable.Make (T)
let of_string = function
| "GET" -> Ok `GET
| "HEAD" -> Ok `HEAD
| "POST" -> Ok `POST
| "PUT" -> Ok `PUT
| "DELETE" -> Ok `DELETE
| "CONNECT" -> Ok `CONNECT
| "OPTIONS" -> Ok `OPTIONS
| "TRACE" -> Ok `TRACE
| "PATCH" -> Ok `PATCH
| meth -> Or_error.error "Invalid HTTP method" meth sexp_of_string
;;
let to_string = function
| `GET -> "GET"
| `HEAD -> "HEAD"
| `POST -> "POST"
| `PUT -> "PUT"
| `DELETE -> "DELETE"
| `CONNECT -> "CONNECT"
| `OPTIONS -> "OPTIONS"
| `TRACE -> "TRACE"
| `PATCH -> "PATCH"
;;
let is_safe = function
| `GET | `HEAD | `OPTIONS | `TRACE -> true
| _ -> false
;;
let is_idempotent = function
| `PUT | `DELETE -> true
| t -> is_safe t
;;
let is_cacheable = function
| `GET | `HEAD | `POST -> true
| _ -> false
;;