Skip to content

Commit

Permalink
method of string
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Dec 10, 2024
1 parent f805330 commit 5024179
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/common/meth.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ let to_string : [< all ] -> string = function
| `OPTIONS -> "OPTIONS"
| `HEAD -> "HEAD"

let of_string s : [> all | `Other of string ] = match s with
| "GET" -> `GET
| "HEAD" -> `HEAD
| "PUT" -> `PUT
| "POST" -> `POST
| "PATCH" -> `PATCH
| "DELETE" -> `DELETE
| "OPTIONS" -> `OPTIONS
| s -> `Other s

let headers l =
let meths = String.concat "," @@ List.map to_string l in
[ "access-control-allow-methods", meths ]
2 changes: 1 addition & 1 deletion src/request/dune
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(public_name ez_api.cohttp_base)
(optional)
(modules ezCohttp_base)
(libraries verbose cohttp-lwt))
(libraries verbose ezAPI cohttp-lwt))

(library
(name ezReq_default)
Expand Down
14 changes: 1 addition & 13 deletions src/request/ezCohttp_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@

open Lwt.Infix

let meth_of_str = function
| "GET" -> `GET
| "HEAD" -> `HEAD
| "PUT" -> `PUT
| "POST" -> `POST
| "CONNECT" -> `CONNECT
| "PATCH" -> `PATCH
| "TRACE" -> `TRACE
| "DELETE" -> `DELETE
| "OPTIONS" -> `OPTIONS
| s -> `Other s

let log ?(meth="GET") url = function
| None ->
if !Verbose.v <> 0 then Format.printf "[ez_api] %s %s@." meth url
Expand All @@ -41,7 +29,7 @@ module Make(Client:Cohttp_lwt.S.Client) = struct
let headers = Option.fold ~none:Cohttp.Header.(add_list (init ()) headers)
~some:(fun ct -> Cohttp.Header.(add_list (init_with "Content-Type" ct) headers))
content_type in
Client.call ?body ~headers (meth_of_str meth)
Client.call ?body ~headers (EzAPI.Meth.of_string meth)
(Uri.of_string url) >>= fun (resp, body) ->
let code = resp |> Cohttp.Response.status |> Cohttp.Code.code_of_status in
Cohttp_lwt.Body.to_string body >|= fun body ->
Expand Down

0 comments on commit 5024179

Please sign in to comment.