This commit is contained in:
Simon Cruanes 2019-12-03 17:38:56 -06:00
parent 948b5e6389
commit aa35e324e6
2 changed files with 2 additions and 7 deletions

View file

@ -577,7 +577,7 @@ module Response = struct
let output_ (oc:out_channel) (self:t) : unit = let output_ (oc:out_channel) (self:t) : unit =
Printf.fprintf oc "HTTP/1.1 %d %s\r\n" self.code (Response_code.descr self.code); Printf.fprintf oc "HTTP/1.1 %d %s\r\n" self.code (Response_code.descr self.code);
List.iter (fun (k,v) -> Printf.fprintf oc "%s: %s\r\n" k v) self.headers; List.iter (fun (k,v) -> Printf.fprintf oc "%s: %s\r\n" k v) self.headers;
Printf.fprintf oc "\r\n"; output_string oc "\r\n";
begin match self.body with begin match self.body with
| `String "" -> () | `String "" -> ()
| `String s -> output_string oc s; | `String s -> output_string oc s;

View file

@ -1,11 +1,6 @@
module S = Tiny_httpd module S = Tiny_httpd
let debug_ k =
if None<>Sys.getenv_opt "HTTP_DBG" then (
k (fun fmt -> Printf.kfprintf (fun oc -> k (Printf.fprintf oc)) stdout fmt)
)
let () = let () =
let port_ = ref 8080 in let port_ = ref 8080 in
let j = ref 32 in let j = ref 32 in
@ -24,7 +19,7 @@ let () =
"/echo" (fun req -> S.Response.make_string (Ok (Format.asprintf "echo:@ %a@." S.Request.pp req))); "/echo" (fun req -> S.Response.make_string (Ok (Format.asprintf "echo:@ %a@." S.Request.pp req)));
S.add_path_handler ~meth:`PUT server S.add_path_handler ~meth:`PUT server
"/upload/%s" (fun path req -> "/upload/%s" (fun path req ->
debug_ (fun k->k "start upload %S\n%!" path); S._debug (fun k->k "start upload %S\n%!" path);
try try
let oc = open_out @@ "/tmp/" ^ path in let oc = open_out @@ "/tmp/" ^ path in
output_string oc req.S.Request.body; output_string oc req.S.Request.body;