From 2ba298c989807c0400edc84cc91b5f1741782371 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 25 Mar 2015 15:08:15 -0400 Subject: [PATCH 1/2] Add curl like -X, --request param to cohttp curl Allows to set http methods on requests --- bin/cohttp_curl_lwt.ml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bin/cohttp_curl_lwt.ml b/bin/cohttp_curl_lwt.ml index 7e6e04ed5a..b2ba9dcf10 100644 --- a/bin/cohttp_curl_lwt.ml +++ b/bin/cohttp_curl_lwt.ml @@ -23,10 +23,11 @@ module D = Cohttp_lwt_unix_debug let debug f = if !D.debug_active then f D.debug_print else () -let client uri ofile = +let client uri ofile meth' = debug (fun d -> d "Client with URI %s\n" (Uri.to_string uri)); - debug (fun d -> d "Client GET issued\n"); - Client.get uri >>= fun (resp, body) -> + let meth = Cohttp.Code.method_of_string meth' in + debug (fun d -> d "Client %s issued\n" meth'); + Client.call meth uri >>= fun (resp, body) -> let status = Response.status resp in debug (fun d -> d "Client GET returned: %s\n" (Code.string_of_status status)); (* TODO follow redirects *) @@ -44,12 +45,12 @@ let client uri ofile = | None -> output_body Lwt_io.stdout | Some fname -> Lwt_io.with_file ~mode:Lwt_io.output fname output_body -let run_client verbose ofile uri = +let run_client verbose ofile uri meth = if verbose then ( Cohttp_lwt_unix_debug.debug_active := true; debug (fun d -> d ">>> Debug active"); ); - Lwt_main.run (client uri ofile) + Lwt_main.run (client uri ofile meth) open Cmdliner @@ -63,6 +64,10 @@ let uri = Arg.(required & pos 0 (some loc) None & info [] ~docv:"URI" ~doc:"string of the remote address (e.g. https://google.com)") +let meth = + let doc = "Set http method" in + Arg.(value & opt string "GET" & info ["X"; "request"] ~doc) + let verb = let doc = "Display additional debugging to standard error." in Arg.(value & flag & info ["v"; "verbose"] ~doc) @@ -84,7 +89,7 @@ let cmd = `S "SEE ALSO"; `P "$(b,curl)(1), $(b,wget)(1)" ] in - Term.(pure run_client $ verb $ ofile $ uri), + Term.(pure run_client $ verb $ ofile $ uri $ meth), Term.info "cohttp-curl" ~version:"1.0.0" ~doc ~man let () = From a4ba9f6515d7a37139dc9bbe1f60788b78ab461a Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 26 Mar 2015 21:11:31 -0400 Subject: [PATCH 2/2] sync CHANGES --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 204d78a8dc..1f91b2d756 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,7 @@ New features and bug fixes: * With the Lwt backend, `read` hangs if trying to fetch more than `Sys.max_string_length` (which can be triggered on 32-bit platforms). Read only a maximum that fits into a string (#282). +* `cohttp-curl-lwt` now takes http method as parameter (#288) 0.15.2 (2015-02-15): * When transfer encoding is unknown, read until EOF when body size is unknown. (#241)