mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-05 19:00:32 -05:00
many fixes
This commit is contained in:
parent
de23d9b2a3
commit
7b094b55ad
5 changed files with 13 additions and 11 deletions
|
|
@ -88,8 +88,8 @@ let () =
|
|||
"echo [option]*";
|
||||
|
||||
let server = S.create ~port:!port_ ~max_connections:!j () in
|
||||
Tiny_httpd_camlzip.setup ~compress_above:1024 ~buf_size:(16 * 1024) server;
|
||||
|
||||
Tiny_httpd_camlzip.setup ~compress_above:1024 ~buf_size:(16 * 1024) server;
|
||||
let m_stats, get_stats = middleware_stat () in
|
||||
S.add_middleware server ~stage:(`Stage 1) m_stats;
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ module Out_channel = struct
|
|||
let chunk_encoding ~close_rec (self : t) : t =
|
||||
let flush = self.flush in
|
||||
let close () =
|
||||
(* write an empty chunk to close the stream *)
|
||||
output_string self "0\r\n";
|
||||
(* write another crlf after the stream (see #56) *)
|
||||
output_string self "\r\n";
|
||||
self.flush ();
|
||||
|
|
@ -92,7 +94,8 @@ module Out_channel = struct
|
|||
let output buf i n =
|
||||
if n > 0 then (
|
||||
output_string self (Printf.sprintf "%x\r\n" n);
|
||||
self.output buf i n
|
||||
self.output buf i n;
|
||||
output_string self "\r\n"
|
||||
)
|
||||
in
|
||||
{ flush; close; output }
|
||||
|
|
|
|||
|
|
@ -478,7 +478,7 @@ module Response = struct
|
|||
let self = { self with headers; body } in
|
||||
_debug (fun k ->
|
||||
k "output response: %s"
|
||||
(Format.asprintf "%a" pp { self with body = `String "<…>" }));
|
||||
(Format.asprintf "%a" pp { self with body = `String "<...>" }));
|
||||
|
||||
(* write headers *)
|
||||
List.iter
|
||||
|
|
|
|||
|
|
@ -83,11 +83,10 @@ let rec iter f (self : t) : unit =
|
|||
(iter [@tailcall]) f self
|
||||
)
|
||||
|
||||
let to_chan (oc : out_channel) (self : t) =
|
||||
iter (fun s i len -> output oc s i len) self
|
||||
let to_chan (oc : out_channel) (self : t) = iter (output oc) self
|
||||
|
||||
let to_chan' (oc : IO.Out_channel.t) (self : t) =
|
||||
iter (fun s i len -> IO.Out_channel.output oc s i len) self
|
||||
iter (IO.Out_channel.output oc) self
|
||||
|
||||
let to_writer (self : t) : Tiny_httpd_io.Writer.t =
|
||||
{ write = (fun oc -> to_chan' oc self) }
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ let encode_deflate_writer_ ~buf_size (w : W.t) : W.t =
|
|||
)
|
||||
in
|
||||
|
||||
(* Zlib.Z_NO_FLUSH *)
|
||||
let flush_zlib ~flush (oc : Out.t) =
|
||||
let continue = ref true in
|
||||
while !continue do
|
||||
|
|
@ -91,18 +90,19 @@ let encode_deflate_writer_ ~buf_size (w : W.t) : W.t =
|
|||
let write (oc : Out.t) : unit =
|
||||
let output buf i len = write_zlib ~flush:Zlib.Z_NO_FLUSH oc buf i len in
|
||||
let flush () =
|
||||
flush_zlib oc ~flush:Zlib.Z_SYNC_FLUSH;
|
||||
flush_zlib oc ~flush:Zlib.Z_FINISH;
|
||||
assert (!o_len = 0);
|
||||
oc.flush ()
|
||||
in
|
||||
let close () =
|
||||
flush_zlib oc ~flush:Zlib.Z_FULL_FLUSH;
|
||||
assert (!o_len = 0);
|
||||
flush ();
|
||||
Zlib.deflate_end zlib_str;
|
||||
oc.close ()
|
||||
in
|
||||
(* new output channel that compresses on the fly *)
|
||||
let oc' = { Out.flush; close; output } in
|
||||
w.write oc'
|
||||
w.write oc';
|
||||
oc'.close ()
|
||||
in
|
||||
|
||||
W.make ~write ()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue