My agentic slop goes here. Not intended for anyone else!
at main 1.9 kB view raw
1let src = Logs.Src.create "requests.method" ~doc:"HTTP Methods" 2module Log = (val Logs.src_log src : Logs.LOG) 3 4type t = [ 5 | `GET 6 | `POST 7 | `PUT 8 | `DELETE 9 | `HEAD 10 | `OPTIONS 11 | `PATCH 12 | `CONNECT 13 | `TRACE 14 | `Other of string 15] 16 17let to_string = function 18 | `GET -> "GET" 19 | `POST -> "POST" 20 | `PUT -> "PUT" 21 | `DELETE -> "DELETE" 22 | `HEAD -> "HEAD" 23 | `OPTIONS -> "OPTIONS" 24 | `PATCH -> "PATCH" 25 | `CONNECT -> "CONNECT" 26 | `TRACE -> "TRACE" 27 | `Other s -> String.uppercase_ascii s 28 29let of_string s = 30 match String.uppercase_ascii s with 31 | "GET" -> `GET 32 | "POST" -> `POST 33 | "PUT" -> `PUT 34 | "DELETE" -> `DELETE 35 | "HEAD" -> `HEAD 36 | "OPTIONS" -> `OPTIONS 37 | "PATCH" -> `PATCH 38 | "CONNECT" -> `CONNECT 39 | "TRACE" -> `TRACE 40 | other -> `Other other 41 42let pp ppf m = Format.fprintf ppf "%s" (to_string m) 43 44let is_safe = function 45 | `GET | `HEAD | `OPTIONS | `TRACE -> true 46 | `POST | `PUT | `DELETE | `PATCH | `CONNECT | `Other _ -> false 47 48let is_idempotent = function 49 | `GET | `HEAD | `PUT | `DELETE | `OPTIONS | `TRACE -> true 50 | `POST | `PATCH | `CONNECT | `Other _ -> false 51 52let has_request_body = function 53 | `POST | `PUT | `PATCH -> true 54 | `GET | `HEAD | `DELETE | `OPTIONS | `CONNECT | `TRACE -> false 55 | `Other _ -> false (* Conservative default for unknown methods *) 56 57let is_cacheable = function 58 | `GET | `HEAD -> true 59 | `POST -> true (* POST can be cacheable with explicit headers *) 60 | `PUT | `DELETE | `PATCH | `OPTIONS | `CONNECT | `TRACE | `Other _ -> false 61 62let equal m1 m2 = 63 match m1, m2 with 64 | `Other s1, `Other s2 -> String.equal (String.uppercase_ascii s1) (String.uppercase_ascii s2) 65 | m1, m2 -> m1 = m2 66 67let compare m1 m2 = 68 match m1, m2 with 69 | `Other s1, `Other s2 -> String.compare (String.uppercase_ascii s1) (String.uppercase_ascii s2) 70 | m1, m2 -> Stdlib.compare m1 m2