Skip to content

Commit 78143fd

Browse files
committed
Merge pull request #288 from rgrinberg/curl_lwt_x
Add curl like -X, --request param to cohttp curl
2 parents 40b9664 + a4ba9f6 commit 78143fd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ New features and bug fixes:
3535
* With the Lwt backend, `read` hangs if trying to fetch more than
3636
`Sys.max_string_length` (which can be triggered on 32-bit platforms).
3737
Read only a maximum that fits into a string (#282).
38+
* `cohttp-curl-lwt` now takes http method as parameter (#288)
3839

3940
0.15.2 (2015-02-15):
4041
* When transfer encoding is unknown, read until EOF when body size is unknown. (#241)

bin/cohttp_curl_lwt.ml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ module D = Cohttp_lwt_unix_debug
2323

2424
let debug f = if !D.debug_active then f D.debug_print else ()
2525

26-
let client uri ofile =
26+
let client uri ofile meth' =
2727
debug (fun d -> d "Client with URI %s\n" (Uri.to_string uri));
28-
debug (fun d -> d "Client GET issued\n");
29-
Client.get uri >>= fun (resp, body) ->
28+
let meth = Cohttp.Code.method_of_string meth' in
29+
debug (fun d -> d "Client %s issued\n" meth');
30+
Client.call meth uri >>= fun (resp, body) ->
3031
let status = Response.status resp in
3132
debug (fun d -> d "Client GET returned: %s\n" (Code.string_of_status status));
3233
(* TODO follow redirects *)
@@ -44,12 +45,12 @@ let client uri ofile =
4445
| None -> output_body Lwt_io.stdout
4546
| Some fname -> Lwt_io.with_file ~mode:Lwt_io.output fname output_body
4647

47-
let run_client verbose ofile uri =
48+
let run_client verbose ofile uri meth =
4849
if verbose then (
4950
Cohttp_lwt_unix_debug.debug_active := true;
5051
debug (fun d -> d ">>> Debug active");
5152
);
52-
Lwt_main.run (client uri ofile)
53+
Lwt_main.run (client uri ofile meth)
5354

5455
open Cmdliner
5556

@@ -63,6 +64,10 @@ let uri =
6364
Arg.(required & pos 0 (some loc) None & info [] ~docv:"URI"
6465
~doc:"string of the remote address (e.g. https://google.com)")
6566

67+
let meth =
68+
let doc = "Set http method" in
69+
Arg.(value & opt string "GET" & info ["X"; "request"] ~doc)
70+
6671
let verb =
6772
let doc = "Display additional debugging to standard error." in
6873
Arg.(value & flag & info ["v"; "verbose"] ~doc)
@@ -84,7 +89,7 @@ let cmd =
8489
`S "SEE ALSO";
8590
`P "$(b,curl)(1), $(b,wget)(1)" ]
8691
in
87-
Term.(pure run_client $ verb $ ofile $ uri),
92+
Term.(pure run_client $ verb $ ofile $ uri $ meth),
8893
Term.info "cohttp-curl" ~version:"1.0.0" ~doc ~man
8994

9095
let () =

0 commit comments

Comments
 (0)