mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
refactor
This commit is contained in:
parent
948b5e6389
commit
aa35e324e6
2 changed files with 2 additions and 7 deletions
|
|
@ -577,7 +577,7 @@ module Response = struct
|
|||
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);
|
||||
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
|
||||
| `String "" -> ()
|
||||
| `String s -> output_string oc s;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
|
||||
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 port_ = ref 8080 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)));
|
||||
S.add_path_handler ~meth:`PUT server
|
||||
"/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
|
||||
let oc = open_out @@ "/tmp/" ^ path in
|
||||
output_string oc req.S.Request.body;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue