diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index 2f771c8b..2f0819c8 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -507,6 +507,7 @@ val active_connections : t -> int val add_decode_request_cb : t -> (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit +[@@deprecated "use add_middleware"] (** Add a callback for every request. The callback can provide a stream transformer and a new request (with modified headers, typically). @@ -518,6 +519,7 @@ val add_decode_request_cb : val add_encode_response_cb: t -> (unit Request.t -> Response.t -> Response.t option) -> unit +[@@deprecated "use add_middleware"] (** Add a callback for every request/response pair. Similarly to {!add_encode_response_cb} the callback can return a new response, for example to compress it. diff --git a/src/camlzip/Tiny_httpd_camlzip.ml b/src/camlzip/Tiny_httpd_camlzip.ml index 0ff8c20e..d4730f59 100644 --- a/src/camlzip/Tiny_httpd_camlzip.ml +++ b/src/camlzip/Tiny_httpd_camlzip.ml @@ -2,7 +2,7 @@ module S = Tiny_httpd module BS = Tiny_httpd.Byte_stream -let mk_decode_deflate_stream_ ~buf_size () (is:S.byte_stream) : S.byte_stream = +let decode_deflate_stream_ ~buf_size () (is:S.byte_stream) : S.byte_stream = S._debug (fun k->k "wrap stream with deflate.decode"); let buf = Bytes.make buf_size ' ' in let buf_len = ref 0 in @@ -156,7 +156,7 @@ let cb_decode_compressed_stream ~buf_size (req:unit S.Request.t) : _ option = begin match Scanf.sscanf s "deflate, %s" (fun s -> s) with | tr' -> let req' = S.Request.set_header req "Transfer-Encoding" tr' in - Some (req', mk_decode_deflate_stream_ ~buf_size ()) + Some (req', decode_deflate_stream_ ~buf_size ()) | exception _ -> None end | _ -> None @@ -192,6 +192,8 @@ let cb_encode_compressed_stream | `String _ | `Void -> None ) else None +(* TODO: as middleware *) + let setup ?(compress_above=500*1024) ?(buf_size=48 * 1_024) (server:S.t) : unit =