deprecate, add todos

This commit is contained in:
Simon Cruanes 2021-12-09 16:45:07 -05:00
parent 6b0000eb6e
commit 8655200bd7
No known key found for this signature in database
GPG key ID: 4AC01D0849AA62B6
2 changed files with 6 additions and 2 deletions

View file

@ -507,6 +507,7 @@ val active_connections : t -> int
val add_decode_request_cb : val add_decode_request_cb :
t -> t ->
(unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> unit
[@@deprecated "use add_middleware"]
(** Add a callback for every request. (** Add a callback for every request.
The callback can provide a stream transformer and a new request (with The callback can provide a stream transformer and a new request (with
modified headers, typically). modified headers, typically).
@ -518,6 +519,7 @@ val add_decode_request_cb :
val add_encode_response_cb: val add_encode_response_cb:
t -> (unit Request.t -> Response.t -> Response.t option) -> unit t -> (unit Request.t -> Response.t -> Response.t option) -> unit
[@@deprecated "use add_middleware"]
(** Add a callback for every request/response pair. (** Add a callback for every request/response pair.
Similarly to {!add_encode_response_cb} the callback can return a new Similarly to {!add_encode_response_cb} the callback can return a new
response, for example to compress it. response, for example to compress it.

View file

@ -2,7 +2,7 @@
module S = Tiny_httpd module S = Tiny_httpd
module BS = Tiny_httpd.Byte_stream 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"); S._debug (fun k->k "wrap stream with deflate.decode");
let buf = Bytes.make buf_size ' ' in let buf = Bytes.make buf_size ' ' in
let buf_len = ref 0 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 begin match Scanf.sscanf s "deflate, %s" (fun s -> s) with
| tr' -> | tr' ->
let req' = S.Request.set_header req "Transfer-Encoding" tr' in 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 | exception _ -> None
end end
| _ -> None | _ -> None
@ -192,6 +192,8 @@ let cb_encode_compressed_stream
| `String _ | `Void -> None | `String _ | `Void -> None
) else None ) else None
(* TODO: as middleware *)
let setup let setup
?(compress_above=500*1024) ?(compress_above=500*1024)
?(buf_size=48 * 1_024) (server:S.t) : unit = ?(buf_size=48 * 1_024) (server:S.t) : unit =