Skip to content

Commit

Permalink
prepare for 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Aug 8, 2023
1 parent d08fe69 commit ac1c1ab
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 23 deletions.
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
(lang dune 2.0)
(name tiny_httpd)
6 changes: 3 additions & 3 deletions src/Tiny_httpd_buf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ 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.
@since 0.5 *)

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 *)
6 changes: 3 additions & 3 deletions src/Tiny_httpd_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down
4 changes: 2 additions & 2 deletions src/Tiny_httpd_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{b NOTE}: experimental.
@since NEXT_RELEASE
@since 0.14
*)

module Buf = Tiny_httpd_buf
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/Tiny_httpd_pool.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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] *)
Expand Down
14 changes: 7 additions & 7 deletions src/Tiny_httpd_server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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]. *)
Expand Down Expand Up @@ -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)
*)

(**/**)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*)

Expand Down Expand Up @@ -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
Expand All @@ -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 *)

(**/**)

Expand Down
10 changes: 5 additions & 5 deletions src/Tiny_httpd_stream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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 *)
2 changes: 1 addition & 1 deletion tiny_httpd.opam
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
opam-version: "2.0"
version: "0.13"
version: "0.14"
authors: ["Simon Cruanes"]
maintainer: "[email protected]"
license: "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tiny_httpd_camlzip.opam
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
opam-version: "2.0"
version: "0.13"
version: "0.14"
authors: ["Simon Cruanes"]
maintainer: "[email protected]"
license: "MIT"
Expand Down

0 comments on commit ac1c1ab

Please sign in to comment.