diff --git a/src/request/unix/curl/ezCurl_lwt.ml b/src/request/unix/curl/ezCurl_lwt.ml index 76bd07e..16b6578 100644 --- a/src/request/unix/curl/ezCurl_lwt.ml +++ b/src/request/unix/curl/ezCurl_lwt.ml @@ -8,4 +8,31 @@ (* *) (**************************************************************************) -include EzCurl_multi +let make ?msg ?meth ?headers ~url l = + EzCurl_common.log ?meth url msg; + if !Verbose.v land 2 <> 0 then Format.printf "[ez_api] sent:\n%s@." (EzCurl_common.payload_to_string l); + let r () = + let r, c = EzCurl_common.init ?meth ?headers ~url l in + Lwt.map (fun _code -> + let rc = Curl.get_responsecode c in + Curl.cleanup c; + let data = Buffer.contents r in + EzCurl_common.log ~meth:("RECV " ^ string_of_int rc) url msg; + if !Verbose.v land 1 <> 0 then Format.printf "[ez_api] received:\n%s@." data; + if rc >= 200 && rc < 300 then Ok data + else Error (rc, Some data)) + (Curl_lwt.perform c) in + Lwt.catch r (function + | Curl.CurlException (_, i, s) -> Lwt.return (Error (i, Some s)) + | exn -> Lwt.return (Error (-1, Some (Printexc.to_string exn)))) + +module Interface = struct + let get ?(meth="GET") ?headers ?msg url = + make ?msg ~meth ?headers ~url [] + + let post ?(meth="POST") ?(content_type="application/json") ?(content="{}") ?headers + ?msg url = + make ?msg ~meth ?headers ~url [ "", `content content, Some content_type ] +end + +include EzRequest_lwt.Make(Interface) diff --git a/src/request/unix/curl/ezReq_lwt.ml b/src/request/unix/curl/ezReq_lwt.ml index 36ef169..76bd07e 100644 --- a/src/request/unix/curl/ezReq_lwt.ml +++ b/src/request/unix/curl/ezReq_lwt.ml @@ -8,4 +8,4 @@ (* *) (**************************************************************************) -include EzCurl_lwt +include EzCurl_multi diff --git a/src/request/unix/curl/multi/dune b/src/request/unix/curl/multi/dune deleted file mode 100644 index 8c3cfb4..0000000 --- a/src/request/unix/curl/multi/dune +++ /dev/null @@ -1,14 +0,0 @@ -(library - (name ezCurl_multi) - (public_name ez_api.curl_multi) - (optional) - (modules ezCurl_multi) - (libraries verbose curl.lwt ezCurl_common ezRequest_lwt)) - -(library - (name ezCurl_multi_i) - (public_name ez_api.icurl_multi) - (optional) - (modules ezReq_lwt) - (implements ezReq_lwt) - (libraries ezCurl_multi)) diff --git a/src/request/unix/curl/multi/ezCurl_multi.ml b/src/request/unix/curl/multi/ezCurl_multi.ml deleted file mode 100644 index 16b6578..0000000 --- a/src/request/unix/curl/multi/ezCurl_multi.ml +++ /dev/null @@ -1,38 +0,0 @@ -(**************************************************************************) -(* *) -(* Copyright 2018-2022 OCamlPro *) -(* *) -(* All rights reserved. This file is distributed under the terms of the *) -(* GNU Lesser General Public License version 2.1, with the special *) -(* exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -let make ?msg ?meth ?headers ~url l = - EzCurl_common.log ?meth url msg; - if !Verbose.v land 2 <> 0 then Format.printf "[ez_api] sent:\n%s@." (EzCurl_common.payload_to_string l); - let r () = - let r, c = EzCurl_common.init ?meth ?headers ~url l in - Lwt.map (fun _code -> - let rc = Curl.get_responsecode c in - Curl.cleanup c; - let data = Buffer.contents r in - EzCurl_common.log ~meth:("RECV " ^ string_of_int rc) url msg; - if !Verbose.v land 1 <> 0 then Format.printf "[ez_api] received:\n%s@." data; - if rc >= 200 && rc < 300 then Ok data - else Error (rc, Some data)) - (Curl_lwt.perform c) in - Lwt.catch r (function - | Curl.CurlException (_, i, s) -> Lwt.return (Error (i, Some s)) - | exn -> Lwt.return (Error (-1, Some (Printexc.to_string exn)))) - -module Interface = struct - let get ?(meth="GET") ?headers ?msg url = - make ?msg ~meth ?headers ~url [] - - let post ?(meth="POST") ?(content_type="application/json") ?(content="{}") ?headers - ?msg url = - make ?msg ~meth ?headers ~url [ "", `content content, Some content_type ] -end - -include EzRequest_lwt.Make(Interface) diff --git a/src/request/unix/curl/multi/ezReq_lwt.ml b/src/request/unix/curl/multi/ezReq_lwt.ml deleted file mode 100644 index 76bd07e..0000000 --- a/src/request/unix/curl/multi/ezReq_lwt.ml +++ /dev/null @@ -1,11 +0,0 @@ -(**************************************************************************) -(* *) -(* Copyright 2018-2022 OCamlPro *) -(* *) -(* All rights reserved. This file is distributed under the terms of the *) -(* GNU Lesser General Public License version 2.1, with the special *) -(* exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -include EzCurl_multi