Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions bin/cohttp_curl_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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 () =
Expand Down