@@ -23,10 +23,11 @@ module D = Cohttp_lwt_unix_debug
23
23
24
24
let debug f = if ! D. debug_active then f D. debug_print else ()
25
25
26
- let client uri ofile =
26
+ let client uri ofile meth' =
27
27
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 ) ->
30
31
let status = Response. status resp in
31
32
debug (fun d -> d " Client GET returned: %s\n " (Code. string_of_status status));
32
33
(* TODO follow redirects *)
@@ -44,12 +45,12 @@ let client uri ofile =
44
45
| None -> output_body Lwt_io. stdout
45
46
| Some fname -> Lwt_io. with_file ~mode: Lwt_io. output fname output_body
46
47
47
- let run_client verbose ofile uri =
48
+ let run_client verbose ofile uri meth =
48
49
if verbose then (
49
50
Cohttp_lwt_unix_debug. debug_active := true ;
50
51
debug (fun d -> d " >>> Debug active" );
51
52
);
52
- Lwt_main. run (client uri ofile)
53
+ Lwt_main. run (client uri ofile meth )
53
54
54
55
open Cmdliner
55
56
@@ -63,6 +64,10 @@ let uri =
63
64
Arg. (required & pos 0 (some loc) None & info [] ~docv: " URI"
64
65
~doc: " string of the remote address (e.g. https://google.com)" )
65
66
67
+ let meth =
68
+ let doc = " Set http method" in
69
+ Arg. (value & opt string " GET" & info [" X" ; " request" ] ~doc )
70
+
66
71
let verb =
67
72
let doc = " Display additional debugging to standard error." in
68
73
Arg. (value & flag & info [" v" ; " verbose" ] ~doc )
@@ -84,7 +89,7 @@ let cmd =
84
89
`S " SEE ALSO" ;
85
90
`P " $(b,curl)(1), $(b,wget)(1)" ]
86
91
in
87
- Term. (pure run_client $ verb $ ofile $ uri),
92
+ Term. (pure run_client $ verb $ ofile $ uri $ meth ),
88
93
Term. info " cohttp-curl" ~version: " 1.0.0" ~doc ~man
89
94
90
95
let () =
0 commit comments