mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
prepare for 0.14
This commit is contained in:
parent
d08fe6926d
commit
ac1c1ab502
10 changed files with 43 additions and 23 deletions
19
CHANGES.md
19
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
|
## 0.13
|
||||||
|
|
||||||
- feat: `Server.run` takes `?after_init` parameter
|
- feat: `Server.run` takes `?after_init` parameter
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
(lang dune 2.0)
|
(lang dune 2.0)
|
||||||
|
(name tiny_httpd)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ val contents_and_clear : t -> string
|
||||||
|
|
||||||
val add_char : t -> char -> unit
|
val add_char : t -> char -> unit
|
||||||
(** Add a single char.
|
(** Add a single char.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
val add_bytes : t -> bytes -> int -> int -> unit
|
val add_bytes : t -> bytes -> int -> int -> unit
|
||||||
(** Append given bytes slice to the buffer.
|
(** 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
|
val add_string : t -> string -> unit
|
||||||
(** Add string.
|
(** Add string.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
val add_buffer : t -> Buffer.t -> unit
|
val add_buffer : t -> Buffer.t -> unit
|
||||||
(** Append bytes from buffer.
|
(** Append bytes from buffer.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ include Tiny_httpd_html_
|
||||||
(** Write an HTML element to this output.
|
(** Write an HTML element to this output.
|
||||||
@param top if true, add DOCTYPE at the beginning. The top element should then
|
@param top if true, add DOCTYPE at the beginning. The top element should then
|
||||||
be a "html" tag.
|
be a "html" tag.
|
||||||
@since NEXT_RELEASE
|
@since 0.14
|
||||||
*)
|
*)
|
||||||
let to_output ?(top = false) (self : elt) (out : IO.Output.t) : unit =
|
let to_output ?(top = false) (self : elt) (out : IO.Output.t) : unit =
|
||||||
let out = Out.create_of_out out in
|
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
|
let to_string_top = to_string ~top:true
|
||||||
|
|
||||||
(** Write a toplevel element to an output channel.
|
(** Write a toplevel element to an output channel.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
let to_out_channel_top = to_output ~top:true
|
let to_out_channel_top = to_output ~top:true
|
||||||
|
|
||||||
(** Produce a streaming writer from this HTML element.
|
(** Produce a streaming writer from this HTML element.
|
||||||
@param top if true, add a DOCTYPE. See {!to_out_channel}.
|
@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 to_writer ?top (self : elt) : IO.Writer.t =
|
||||||
let write oc = to_output ?top self oc in
|
let write oc = to_output ?top self oc in
|
||||||
IO.Writer.make ~write ()
|
IO.Writer.make ~write ()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
{b NOTE}: experimental.
|
{b NOTE}: experimental.
|
||||||
|
|
||||||
@since NEXT_RELEASE
|
@since 0.14
|
||||||
*)
|
*)
|
||||||
|
|
||||||
module Buf = Tiny_httpd_buf
|
module Buf = Tiny_httpd_buf
|
||||||
|
|
@ -167,7 +167,7 @@ module Writer = struct
|
||||||
This is useful for responses: an http endpoint can return a writer
|
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
|
as its response's body, and output into it as if it were a regular
|
||||||
[out_channel], including controlling calls to [flush].
|
[out_channel], including controlling calls to [flush].
|
||||||
@since NEXT_RELEASE
|
@since 0.14
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let[@inline] make ~write () : t = { write }
|
let[@inline] make ~write () : t = { write }
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
cheap to produce and discard, and will never block waiting for
|
cheap to produce and discard, and will never block waiting for
|
||||||
a resource — it's not a good pool for DB connections.
|
a resource — it's not a good pool for DB connections.
|
||||||
|
|
||||||
@since NEXT_RELEASE. *)
|
@since 0.14. *)
|
||||||
|
|
||||||
type 'a t
|
type 'a t
|
||||||
(** Pool of values of type ['a] *)
|
(** Pool of values of type ['a] *)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ module Request : sig
|
||||||
host: string;
|
host: string;
|
||||||
(** Host header, mandatory. It can also be found in {!headers}. *)
|
(** Host header, mandatory. It can also be found in {!headers}. *)
|
||||||
client_addr: Unix.sockaddr;
|
client_addr: Unix.sockaddr;
|
||||||
(** Client address. Available since NEXT_RELEASE. *)
|
(** Client address. Available since 0.14. *)
|
||||||
headers: Headers.t; (** List of headers. *)
|
headers: Headers.t; (** List of headers. *)
|
||||||
http_version: int * int;
|
http_version: int * int;
|
||||||
(** HTTP version. This should be either [1, 0] or [1, 1]. *)
|
(** 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.
|
(** Read the whole body into a string. Potentially blocking.
|
||||||
|
|
||||||
@param buf_size initial size of underlying buffer (since 0.11)
|
@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.
|
- [`Void] replies with no body.
|
||||||
- [`Writer w] replies with a body created by the writer [w], using
|
- [`Writer w] replies with a body created by the writer [w], using
|
||||||
a chunked encoding.
|
a chunked encoding.
|
||||||
It is available since NEXT_RELEASE.
|
It is available since 0.14.
|
||||||
*)
|
*)
|
||||||
|
|
||||||
type t = private {
|
type t = private {
|
||||||
|
|
@ -477,7 +477,7 @@ val create_from :
|
||||||
@param buf_size size for buffers (since 0.11)
|
@param buf_size size for buffers (since 0.11)
|
||||||
@param middlewares see {!add_middleware} for more details.
|
@param middlewares see {!add_middleware} for more details.
|
||||||
|
|
||||||
@since NEXT_RELEASE
|
@since 0.14
|
||||||
*)
|
*)
|
||||||
|
|
||||||
val addr : t -> string
|
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
|
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]
|
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.
|
a string if needed.
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
@ -642,7 +642,7 @@ val add_route_server_sent_handler :
|
||||||
|
|
||||||
val running : t -> bool
|
val running : t -> bool
|
||||||
(** Is the server running?
|
(** Is the server running?
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
val stop : t -> unit
|
val stop : t -> unit
|
||||||
(** Ask the server to stop. This might not have an immediate effect
|
(** 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
|
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
|
(** [run_exn s] is like [run s] but re-raises an exception if the server exits
|
||||||
with an error.
|
with an error.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ val empty : t
|
||||||
|
|
||||||
val of_input : ?buf_size:int -> Tiny_httpd_io.Input.t -> t
|
val of_input : ?buf_size:int -> Tiny_httpd_io.Input.t -> t
|
||||||
(** Make a buffered stream from the given channel.
|
(** Make a buffered stream from the given channel.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
val of_chan : ?buf_size:int -> in_channel -> t
|
val of_chan : ?buf_size:int -> in_channel -> t
|
||||||
(** Make a buffered stream from the given channel. *)
|
(** 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
|
val to_chan' : Tiny_httpd_io.Output.t -> t -> unit
|
||||||
(** Write to the IO channel.
|
(** Write to the IO channel.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
val to_writer : t -> Tiny_httpd_io.Writer.t
|
val to_writer : t -> Tiny_httpd_io.Writer.t
|
||||||
(** Turn this stream into a writer.
|
(** Turn this stream into a writer.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
||||||
val make :
|
val make :
|
||||||
?bs:bytes ->
|
?bs:bytes ->
|
||||||
|
|
@ -151,9 +151,9 @@ val read_exactly :
|
||||||
|
|
||||||
val output_chunked : ?buf:Tiny_httpd_buf.t -> out_channel -> t -> unit
|
val output_chunked : ?buf:Tiny_httpd_buf.t -> out_channel -> t -> unit
|
||||||
(** Write the stream into the channel, using the chunked encoding.
|
(** 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' :
|
val output_chunked' :
|
||||||
?buf:Tiny_httpd_buf.t -> Tiny_httpd_io.Output.t -> t -> unit
|
?buf:Tiny_httpd_buf.t -> Tiny_httpd_io.Output.t -> t -> unit
|
||||||
(** Write the stream into the channel, using the chunked encoding.
|
(** Write the stream into the channel, using the chunked encoding.
|
||||||
@since NEXT_RELEASE *)
|
@since 0.14 *)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
opam-version: "2.0"
|
opam-version: "2.0"
|
||||||
version: "0.13"
|
version: "0.14"
|
||||||
authors: ["Simon Cruanes"]
|
authors: ["Simon Cruanes"]
|
||||||
maintainer: "simon.cruanes.2007@m4x.org"
|
maintainer: "simon.cruanes.2007@m4x.org"
|
||||||
license: "MIT"
|
license: "MIT"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
opam-version: "2.0"
|
opam-version: "2.0"
|
||||||
version: "0.13"
|
version: "0.14"
|
||||||
authors: ["Simon Cruanes"]
|
authors: ["Simon Cruanes"]
|
||||||
maintainer: "simon.cruanes.2007@m4x.org"
|
maintainer: "simon.cruanes.2007@m4x.org"
|
||||||
license: "MIT"
|
license: "MIT"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue