From ac1c1ab502d368c1d6d58010e6629b9369c1dc2f Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 8 Aug 2023 16:45:28 -0400 Subject: [PATCH] prepare for 0.14 --- CHANGES.md | 19 +++++++++++++++++++ dune-project | 1 + src/Tiny_httpd_buf.mli | 6 +++--- src/Tiny_httpd_html.ml | 6 +++--- src/Tiny_httpd_io.ml | 4 ++-- src/Tiny_httpd_pool.mli | 2 +- src/Tiny_httpd_server.mli | 14 +++++++------- src/Tiny_httpd_stream.mli | 10 +++++----- tiny_httpd.opam | 2 +- tiny_httpd_camlzip.opam | 2 +- 10 files changed, 43 insertions(+), 23 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f6b17661..50f0a717 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,22 @@ + +## 0.14 + +- breaking: `set_top_handler` takes a stream request, for more generality + +- Don't let client handling threads handle SIGINT/SIGHUP +- improve termination behavior (wait for threads to terminate when shutting down server) +- Preserve client address down to Request.t +- add `Tiny_httpd_io` module, abstraction over IOs (output/input) as better IO channels + than the stdlib's +- add `Tiny_httpd_html.to_writer` +- add `IO.Writer.t`, a push based stream. +- add `Server.run_exn` +- add `Tiny_httpd_pool` +- server: add `IO_BACKEND` abstraction; implement a unix version of it + +- perf: use TCP_NODELAY for client sockets +- perf: use a resource pool to recycle buffers, improves memory consumption and GC pressure + ## 0.13 - feat: `Server.run` takes `?after_init` parameter diff --git a/dune-project b/dune-project index 929c696e..967e90cf 100644 --- a/dune-project +++ b/dune-project @@ -1 +1,2 @@ (lang dune 2.0) +(name tiny_httpd) diff --git a/src/Tiny_httpd_buf.mli b/src/Tiny_httpd_buf.mli index 702cc787..e4d2a5c5 100644 --- a/src/Tiny_httpd_buf.mli +++ b/src/Tiny_httpd_buf.mli @@ -23,7 +23,7 @@ val contents_and_clear : t -> string val add_char : t -> char -> unit (** Add a single char. - @since NEXT_RELEASE *) + @since 0.14 *) val add_bytes : t -> bytes -> int -> int -> unit (** Append given bytes slice to the buffer. @@ -31,8 +31,8 @@ val add_bytes : t -> bytes -> int -> int -> unit val add_string : t -> string -> unit (** Add string. - @since NEXT_RELEASE *) + @since 0.14 *) val add_buffer : t -> Buffer.t -> unit (** Append bytes from buffer. - @since NEXT_RELEASE *) + @since 0.14 *) diff --git a/src/Tiny_httpd_html.ml b/src/Tiny_httpd_html.ml index 7c30da11..61f0416b 100644 --- a/src/Tiny_httpd_html.ml +++ b/src/Tiny_httpd_html.ml @@ -14,7 +14,7 @@ include Tiny_httpd_html_ (** Write an HTML element to this output. @param top if true, add DOCTYPE at the beginning. The top element should then be a "html" tag. - @since NEXT_RELEASE + @since 0.14 *) let to_output ?(top = false) (self : elt) (out : IO.Output.t) : unit = let out = Out.create_of_out out in @@ -49,12 +49,12 @@ let to_string_l (l : elt list) = let to_string_top = to_string ~top:true (** Write a toplevel element to an output channel. - @since NEXT_RELEASE *) + @since 0.14 *) let to_out_channel_top = to_output ~top:true (** Produce a streaming writer from this HTML element. @param top if true, add a DOCTYPE. See {!to_out_channel}. - @since NEXT_RELEASE *) + @since 0.14 *) let to_writer ?top (self : elt) : IO.Writer.t = let write oc = to_output ?top self oc in IO.Writer.make ~write () diff --git a/src/Tiny_httpd_io.ml b/src/Tiny_httpd_io.ml index 507d9544..654d8608 100644 --- a/src/Tiny_httpd_io.ml +++ b/src/Tiny_httpd_io.ml @@ -5,7 +5,7 @@ {b NOTE}: experimental. - @since NEXT_RELEASE + @since 0.14 *) module Buf = Tiny_httpd_buf @@ -167,7 +167,7 @@ module Writer = struct This is useful for responses: an http endpoint can return a writer as its response's body, and output into it as if it were a regular [out_channel], including controlling calls to [flush]. - @since NEXT_RELEASE + @since 0.14 *) let[@inline] make ~write () : t = { write } diff --git a/src/Tiny_httpd_pool.mli b/src/Tiny_httpd_pool.mli index ab9aaa41..a2418e11 100644 --- a/src/Tiny_httpd_pool.mli +++ b/src/Tiny_httpd_pool.mli @@ -5,7 +5,7 @@ cheap to produce and discard, and will never block waiting for a resource — it's not a good pool for DB connections. - @since NEXT_RELEASE. *) + @since 0.14. *) type 'a t (** Pool of values of type ['a] *) diff --git a/src/Tiny_httpd_server.mli b/src/Tiny_httpd_server.mli index f3c2f6b9..f0aef7fa 100644 --- a/src/Tiny_httpd_server.mli +++ b/src/Tiny_httpd_server.mli @@ -68,7 +68,7 @@ module Request : sig host: string; (** Host header, mandatory. It can also be found in {!headers}. *) client_addr: Unix.sockaddr; - (** Client address. Available since NEXT_RELEASE. *) + (** Client address. Available since 0.14. *) headers: Headers.t; (** List of headers. *) http_version: int * int; (** HTTP version. This should be either [1, 0] or [1, 1]. *) @@ -155,7 +155,7 @@ module Request : sig (** Read the whole body into a string. Potentially blocking. @param buf_size initial size of underlying buffer (since 0.11) - @param buf the initial buffer (since NEXT_RELEASE) + @param buf the initial buffer (since 0.14) *) (**/**) @@ -213,7 +213,7 @@ module Response : sig - [`Void] replies with no body. - [`Writer w] replies with a body created by the writer [w], using a chunked encoding. - It is available since NEXT_RELEASE. + It is available since 0.14. *) type t = private { @@ -477,7 +477,7 @@ val create_from : @param buf_size size for buffers (since 0.11) @param middlewares see {!add_middleware} for more details. - @since NEXT_RELEASE + @since 0.14 *) val addr : t -> string @@ -540,7 +540,7 @@ val set_top_handler : t -> (byte_stream Request.t -> Response.t) -> unit If no top handler is installed, unhandled paths will return a [404] not found This used to take a [string Request.t] but it now takes a [byte_stream Request.t] - since NEXT_RELEASE . Use {!Request.read_body_full} to read the body into + since 0.14 . Use {!Request.read_body_full} to read the body into a string if needed. *) @@ -642,7 +642,7 @@ val add_route_server_sent_handler : val running : t -> bool (** Is the server running? - @since NEXT_RELEASE *) + @since 0.14 *) val stop : t -> unit (** Ask the server to stop. This might not have an immediate effect @@ -662,7 +662,7 @@ val run : ?after_init:(unit -> unit) -> t -> (unit, exn) result val run_exn : ?after_init:(unit -> unit) -> t -> unit (** [run_exn s] is like [run s] but re-raises an exception if the server exits with an error. - @since NEXT_RELEASE *) + @since 0.14 *) (**/**) diff --git a/src/Tiny_httpd_stream.mli b/src/Tiny_httpd_stream.mli index 5d75380c..23f8c298 100644 --- a/src/Tiny_httpd_stream.mli +++ b/src/Tiny_httpd_stream.mli @@ -66,7 +66,7 @@ val empty : t val of_input : ?buf_size:int -> Tiny_httpd_io.Input.t -> t (** Make a buffered stream from the given channel. - @since NEXT_RELEASE *) + @since 0.14 *) val of_chan : ?buf_size:int -> in_channel -> t (** Make a buffered stream from the given channel. *) @@ -96,11 +96,11 @@ val to_chan : out_channel -> t -> unit val to_chan' : Tiny_httpd_io.Output.t -> t -> unit (** Write to the IO channel. - @since NEXT_RELEASE *) + @since 0.14 *) val to_writer : t -> Tiny_httpd_io.Writer.t (** Turn this stream into a writer. - @since NEXT_RELEASE *) + @since 0.14 *) val make : ?bs:bytes -> @@ -151,9 +151,9 @@ val read_exactly : val output_chunked : ?buf:Tiny_httpd_buf.t -> out_channel -> t -> unit (** Write the stream into the channel, using the chunked encoding. - @param buf optional buffer for chunking (since NEXT_RELEASE) *) + @param buf optional buffer for chunking (since 0.14) *) val output_chunked' : ?buf:Tiny_httpd_buf.t -> Tiny_httpd_io.Output.t -> t -> unit (** Write the stream into the channel, using the chunked encoding. - @since NEXT_RELEASE *) + @since 0.14 *) diff --git a/tiny_httpd.opam b/tiny_httpd.opam index 7409ccee..170a0ac4 100644 --- a/tiny_httpd.opam +++ b/tiny_httpd.opam @@ -1,5 +1,5 @@ opam-version: "2.0" -version: "0.13" +version: "0.14" authors: ["Simon Cruanes"] maintainer: "simon.cruanes.2007@m4x.org" license: "MIT" diff --git a/tiny_httpd_camlzip.opam b/tiny_httpd_camlzip.opam index a6ca34f9..5f175b95 100644 --- a/tiny_httpd_camlzip.opam +++ b/tiny_httpd_camlzip.opam @@ -1,5 +1,5 @@ opam-version: "2.0" -version: "0.13" +version: "0.14" authors: ["Simon Cruanes"] maintainer: "simon.cruanes.2007@m4x.org" license: "MIT"