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