diff --git a/hmap/Hmap/Key/index.html b/hmap/Hmap/Key/index.html new file mode 100644 index 00000000..9a182a4d --- /dev/null +++ b/hmap/Hmap/Key/index.html @@ -0,0 +1,2 @@ + +Key (hmap.Hmap.Key)

Module Hmap.Key

Keys.

Keys

val create : unit -> 'a key

create () is a new key.

Existential keys

Exisential keys allows to compare keys. This can be useful for functions like filter.

type t

The type for existential keys.

val hide_type : 'a key -> t

hide_type k is an existential key for k.

val equal : t -> t -> bool

equal k k' is true iff k and k' are the same key.

val compare : t -> t -> int

compare k k' is a total order on keys compatible with equal.

diff --git a/hmap/Hmap/Make/Key/index.html b/hmap/Hmap/Make/Key/index.html new file mode 100644 index 00000000..44bfb6d7 --- /dev/null +++ b/hmap/Hmap/Make/Key/index.html @@ -0,0 +1,2 @@ + +Key (hmap.Hmap.Make.Key)

Module Make.Key

Keys.

Keys

type 'a info = 'a Key_info.t

The type for key information.

val create : 'a info -> 'a key

create i is a new key with information i.

val info : 'a key -> 'a info

info k is k's information.

Existential keys

Exisential keys allow to compare keys. This can be useful for functions like filter.

type t

The type for existential keys.

val hide_type : 'a key -> t

hide_type k is an existential key for k.

val equal : t -> t -> bool

equal k k' is true iff k and k' are the same key.

val compare : t -> t -> int

compare k k' is a total order on keys compatible with equal.

diff --git a/hmap/Hmap/Make/argument-1-Key_info/index.html b/hmap/Hmap/Make/argument-1-Key_info/index.html new file mode 100644 index 00000000..4a4e1de6 --- /dev/null +++ b/hmap/Hmap/Make/argument-1-Key_info/index.html @@ -0,0 +1,2 @@ + +Key_info (hmap.Hmap.Make.Key_info)

Parameter Make.Key_info

type 'a t

The type for key information.

diff --git a/hmap/Hmap/Make/index.html b/hmap/Hmap/Make/index.html new file mode 100644 index 00000000..9b512b43 --- /dev/null +++ b/hmap/Hmap/Make/index.html @@ -0,0 +1,2 @@ + +Make (hmap.Hmap.Make)

Module Hmap.Make

Functor for heterogeneous maps whose keys hold information of type Key_info.t

Parameters

Signature

Keys

type 'a key

The type for keys whose lookup value is of type 'a.

module Key : sig ... end

Keys.

Maps

type t

The type for heterogeneous value maps.

val empty : t

empty is the empty map.

val is_empty : t -> bool

is_empty m is true iff m is empty.

val mem : 'a key -> t -> bool

mem k m is true iff k is bound in m.

val add : 'a key -> 'a -> t -> t

add k v m is m with k bound to v.

val singleton : 'a key -> 'a -> t

singleton k v is add k v empty.

val rem : 'a key -> t -> t

rem k m is m with k unbound.

val find : 'a key -> t -> 'a option

find k m is the value of k's binding in m, if any.

val get : 'a key -> t -> 'a

get k m is the value of k's binding in m.

  • raises Invalid_argument

    if k is not bound in m.

type binding =
  1. | B : 'a key * 'a -> binding

The type for bindings.

val iter : (binding -> unit) -> t -> unit

iter f m applies f to all bindings of m.

val fold : (binding -> 'a -> 'a) -> t -> 'a -> 'a

fold f m acc folds over the bindings of m with f, starting with acc

val for_all : (binding -> bool) -> t -> bool

for_all p m is true iff all bindings of m satisfy p.

val exists : (binding -> bool) -> t -> bool

exists p m is true iff there exists a bindings of m that satisfies p.

val filter : (binding -> bool) -> t -> t

filter p m are the bindings of m that satisfy p.

val cardinal : t -> int

cardinal m is the number of bindings in m.

val any_binding : t -> binding option

any_binding m is a binding of m (if not empty).

val get_any_binding : t -> binding

get_any_binding m is a binding of m.

  • raises Invalid_argument

    if m is empty.

diff --git a/hmap/Hmap/index.html b/hmap/Hmap/index.html new file mode 100644 index 00000000..750002b7 --- /dev/null +++ b/hmap/Hmap/index.html @@ -0,0 +1,2 @@ + +Hmap (hmap.Hmap)

Module Hmap

Heterogeneous value maps.

v0.8.1 - homepage

Keys

type 'a key

The type for keys whose lookup value is of type 'a.

module Key : sig ... end

Keys.

Maps

type t

The type for heterogeneous value maps.

val empty : t

empty is the empty map.

val is_empty : t -> bool

is_empty m is true iff m is empty.

val mem : 'a key -> t -> bool

mem k m is true iff k is bound in m.

val add : 'a key -> 'a -> t -> t

add k v m is m with k bound to v.

val singleton : 'a key -> 'a -> t

singleton k v is add k v empty.

val rem : 'a key -> t -> t

rem k m is m with k unbound.

val find : 'a key -> t -> 'a option

find k m is the value of k's binding in m, if any.

val get : 'a key -> t -> 'a

get k m is the value of k's binding in m.

  • raises Invalid_argument

    if k is not bound in m.

type binding =
  1. | B : 'a key * 'a -> binding

The type for bindings.

val iter : (binding -> unit) -> t -> unit

iter f m applies f to all bindings of m.

val fold : (binding -> 'a -> 'a) -> t -> 'a -> 'a

fold f m acc folds over the bindings of m with f, starting with acc

val for_all : (binding -> bool) -> t -> bool

for_all p m is true iff all bindings of m satisfy p.

val exists : (binding -> bool) -> t -> bool

exists p m is true iff there exists a bindings of m that satisfies p.

val filter : (binding -> bool) -> t -> t

filter p m are the bindings of m that satisfy p.

val cardinal : t -> int

cardinal m is the number of bindings in m.

val any_binding : t -> binding option

any_binding m is a binding of m (if not empty).

val get_any_binding : t -> binding

get_any_binding m is a binding of m.

  • raises Invalid_argument

    if m is empty.

Functorial interface

The functorial interface allows to associate more information to the keys. For example a key name or a key value pretty-printer.

module type KEY_INFO = sig ... end

The type for key information.

module type S = sig ... end

Output signature of the functor Make

module Make (Key_info : KEY_INFO) : S with type 'a Key.info = 'a Key_info.t

Functor for heterogeneous maps whose keys hold information of type Key_info.t

diff --git a/hmap/Hmap/module-type-KEY_INFO/index.html b/hmap/Hmap/module-type-KEY_INFO/index.html new file mode 100644 index 00000000..1f77dada --- /dev/null +++ b/hmap/Hmap/module-type-KEY_INFO/index.html @@ -0,0 +1,2 @@ + +KEY_INFO (hmap.Hmap.KEY_INFO)

Module type Hmap.KEY_INFO

The type for key information.

type 'a t

The type for key information.

diff --git a/hmap/Hmap/module-type-S/Key/index.html b/hmap/Hmap/module-type-S/Key/index.html new file mode 100644 index 00000000..aee2182f --- /dev/null +++ b/hmap/Hmap/module-type-S/Key/index.html @@ -0,0 +1,2 @@ + +Key (hmap.Hmap.S.Key)

Module S.Key

Keys.

Keys

type 'a info

The type for key information.

val create : 'a info -> 'a key

create i is a new key with information i.

val info : 'a key -> 'a info

info k is k's information.

Existential keys

Exisential keys allow to compare keys. This can be useful for functions like filter.

type t

The type for existential keys.

val hide_type : 'a key -> t

hide_type k is an existential key for k.

val equal : t -> t -> bool

equal k k' is true iff k and k' are the same key.

val compare : t -> t -> int

compare k k' is a total order on keys compatible with equal.

diff --git a/hmap/Hmap/module-type-S/index.html b/hmap/Hmap/module-type-S/index.html new file mode 100644 index 00000000..38aefbd7 --- /dev/null +++ b/hmap/Hmap/module-type-S/index.html @@ -0,0 +1,2 @@ + +S (hmap.Hmap.S)

Module type Hmap.S

Output signature of the functor Make

Keys

type 'a key

The type for keys whose lookup value is of type 'a.

module Key : sig ... end

Keys.

Maps

type t

The type for heterogeneous value maps.

val empty : t

empty is the empty map.

val is_empty : t -> bool

is_empty m is true iff m is empty.

val mem : 'a key -> t -> bool

mem k m is true iff k is bound in m.

val add : 'a key -> 'a -> t -> t

add k v m is m with k bound to v.

val singleton : 'a key -> 'a -> t

singleton k v is add k v empty.

val rem : 'a key -> t -> t

rem k m is m with k unbound.

val find : 'a key -> t -> 'a option

find k m is the value of k's binding in m, if any.

val get : 'a key -> t -> 'a

get k m is the value of k's binding in m.

  • raises Invalid_argument

    if k is not bound in m.

type binding =
  1. | B : 'a key * 'a -> binding

The type for bindings.

val iter : (binding -> unit) -> t -> unit

iter f m applies f to all bindings of m.

val fold : (binding -> 'a -> 'a) -> t -> 'a -> 'a

fold f m acc folds over the bindings of m with f, starting with acc

val for_all : (binding -> bool) -> t -> bool

for_all p m is true iff all bindings of m satisfy p.

val exists : (binding -> bool) -> t -> bool

exists p m is true iff there exists a bindings of m that satisfies p.

val filter : (binding -> bool) -> t -> t

filter p m are the bindings of m that satisfy p.

val cardinal : t -> int

cardinal m is the number of bindings in m.

val any_binding : t -> binding option

any_binding m is a binding of m (if not empty).

val get_any_binding : t -> binding

get_any_binding m is a binding of m.

  • raises Invalid_argument

    if m is empty.

diff --git a/hmap/_doc-dir/CHANGES.md b/hmap/_doc-dir/CHANGES.md new file mode 100644 index 00000000..ac21d5bc --- /dev/null +++ b/hmap/_doc-dir/CHANGES.md @@ -0,0 +1,9 @@ +v0.8.1 2017-10-03 Zagreb +------------------------ + +* Build depend on topkg. + +v0.8.0 2016-03-08 La Forclaz (VS) +--------------------------------- + +First release. diff --git a/hmap/_doc-dir/LICENSE.md b/hmap/_doc-dir/LICENSE.md new file mode 100644 index 00000000..ca386f07 --- /dev/null +++ b/hmap/_doc-dir/LICENSE.md @@ -0,0 +1,13 @@ + Copyright (c) 2016 Daniel C. Bünzli + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/hmap/_doc-dir/README.md b/hmap/_doc-dir/README.md new file mode 100644 index 00000000..3f4d1cad --- /dev/null +++ b/hmap/_doc-dir/README.md @@ -0,0 +1,43 @@ +Hmap — Heterogeneous value maps for OCaml +------------------------------------------------------------------------------- +v0.8.1 + +Hmap provides heterogeneous value maps for OCaml. These maps bind keys +to values with arbitrary types. Keys witness the type of the value +they are bound to which allows to add and lookup bindings in a type +safe manner. + +Hmap has no dependency and is distributed under the ISC license. + +Home page: http://erratique.ch/software/hmap +Contact: Daniel Bünzli `` + +## Installation + +Hmap can be installed with `opam`: + + opam install hmap + +If you don't use `opam` consult the [`opam`](opam) file for build +instructions. + +## Documentation + +The documentation and API reference is automatically generated by +`ocamldoc` from the interfaces. It can be consulted [online][doc] +and there is a generated version in the `doc` directory of the +distribution. + +[doc]: http://erratique.ch/software/hmap/doc + +## Sample programs + +If you installed Hmap with `opam` sample programs are located in +the directory `opam config var hmap:doc`. + +In the distribution sample programs and tests are located in the +[`test`](test) directory of the distribution. They can be built an run +with + + topkg build --tests true + topkg test diff --git a/hmap/index.html b/hmap/index.html new file mode 100644 index 00000000..2b0040ca --- /dev/null +++ b/hmap/index.html @@ -0,0 +1,2 @@ + +index (hmap.index)

Package hmap

Package info

changes-files
license-files
readme-files
diff --git a/index.html b/index.html index b027a7a3..defd56c6 100644 --- a/index.html +++ b/index.html @@ -1,2 +1,2 @@ -_opam

OCaml package documentation

Browse by name, by tag, the standard library and the OCaml manual (online, latest version).

Generated for /home/runner/work/tiny_httpd/tiny_httpd/_opam/lib

Packages by name

Packages by tag

\ No newline at end of file +_opam

OCaml package documentation

Browse by name, by tag, the standard library and the OCaml manual (online, latest version).

Generated for /home/runner/work/tiny_httpd/tiny_httpd/_opam/lib

Packages by name

Packages by tag

\ No newline at end of file diff --git a/iostream/Iostream/In/class-empty/index.html b/iostream/Iostream/In/class-empty/index.html new file mode 100644 index 00000000..29dd4981 --- /dev/null +++ b/iostream/Iostream/In/class-empty/index.html @@ -0,0 +1,2 @@ + +empty (iostream.Iostream.In.empty)

Class In.empty

method input : bytes -> int -> int -> int

Read into the slice. Returns 0 only if the stream is closed.

method close : unit -> unit

Close the input. Must be idempotent.

diff --git a/iostream/Iostream/In/class-of_bytes/index.html b/iostream/Iostream/In/class-of_bytes/index.html new file mode 100644 index 00000000..a1e2c37b --- /dev/null +++ b/iostream/Iostream/In/class-of_bytes/index.html @@ -0,0 +1,2 @@ + +of_bytes (iostream.Iostream.In.of_bytes)

Class In.of_bytes

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/In/class-of_in_channel/index.html b/iostream/Iostream/In/class-of_in_channel/index.html new file mode 100644 index 00000000..6a836819 --- /dev/null +++ b/iostream/Iostream/In/class-of_in_channel/index.html @@ -0,0 +1,2 @@ + +of_in_channel (iostream.Iostream.In.of_in_channel)

Class In.of_in_channel

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/In/class-of_string/index.html b/iostream/Iostream/In/class-of_string/index.html new file mode 100644 index 00000000..385405b5 --- /dev/null +++ b/iostream/Iostream/In/class-of_string/index.html @@ -0,0 +1,2 @@ + +of_string (iostream.Iostream.In.of_string)

Class In.of_string

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/In/class-open_file/index.html b/iostream/Iostream/In/class-open_file/index.html new file mode 100644 index 00000000..88f60309 --- /dev/null +++ b/iostream/Iostream/In/class-open_file/index.html @@ -0,0 +1,2 @@ + +open_file (iostream.Iostream.In.open_file)

Class In.open_file

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/In/class-type-t/index.html b/iostream/Iostream/In/class-type-t/index.html new file mode 100644 index 00000000..b4226763 --- /dev/null +++ b/iostream/Iostream/In/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (iostream.Iostream.In.t)

Class type In.t

An input stream, i.e an incoming stream of bytes.

This can be a string, an int_channel, an Unix.file_descr, a decompression wrapper around another input stream, etc.

method input : bytes -> int -> int -> int

Read into the slice. Returns 0 only if the stream is closed.

method close : unit -> unit

Close the input. Must be idempotent.

diff --git a/iostream/Iostream/In/class-type-t_seekable/index.html b/iostream/Iostream/In/class-type-t_seekable/index.html new file mode 100644 index 00000000..8ddbf4df --- /dev/null +++ b/iostream/Iostream/In/class-type-t_seekable/index.html @@ -0,0 +1,2 @@ + +t_seekable (iostream.Iostream.In.t_seekable)

Class type In.t_seekable

An input stream that is also seekable.

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/In/index.html b/iostream/Iostream/In/index.html new file mode 100644 index 00000000..05a335a0 --- /dev/null +++ b/iostream/Iostream/In/index.html @@ -0,0 +1,18 @@ + +In (iostream.Iostream.In)

Module Iostream.In

Input stream.

class type t = object ... end

An input stream, i.e an incoming stream of bytes.

class type t_seekable = object ... end

An input stream that is also seekable.

val create : + ?close:(unit -> unit) -> + input:(bytes -> int -> int -> int) -> + unit -> + t
class empty : t
val empty : t

Empty input, contains 0 bytes.

class of_in_channel : ?close_noerr:bool -> in_channel -> t_seekable
val of_in_channel : ?close_noerr:bool -> in_channel -> t_seekable

Wrap a standard input channel.

class open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string -> + t_seekable
val open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + t_seekable
val with_open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + (t_seekable -> 'a) -> + 'a
class of_string : ?off:int -> ?len:int -> string -> t_seekable
val of_string : ?off:int -> ?len:int -> string -> t_seekable

An input channel reading from the string.

  • parameter offset

    initial offset in the string. Default 0.

  • parameter len

    the length of the slice we read from. Default String.length s - off.

class of_bytes : ?off:int -> ?len:int -> bytes -> t_seekable
val of_bytes : ?off:int -> ?len:int -> bytes -> t_seekable

An input channel reading from the bytes buffer. See of_string for more details.

val input : t -> bytes -> int -> int -> int

Read bytes into the given buffer. This returns 0 only if the stream has reached its end.

  • raises Invalid_argument

    if the arguments do not denote a valid slice.

val input_all_into_buffer : t -> Stdlib.Buffer.t -> unit

Read the whole content into the given buffer.

  • since 0.2
val input_all : ?buf:bytes -> t -> string

input_all ic reads the whole content of ic into a string.

  • parameter buf

    the initial buffer to use internally.

  • since 0.2
val really_input : t -> bytes -> int -> int -> unit

Same as input, but reads exactly the demanded amount of bytes.

  • raises Invalid_argument

    if the arguments do not denote a valid slice.

  • raises End_of_file

    if the input does not contain enough data.

  • since 0.2
val really_input_string : t -> int -> string

really_input_string ic n reads exactly n bytes of ic and returns them as a string.

  • raises End_of_file

    if the input does not contain enough data.

  • since 0.2
val concat : t list -> t

Read from each stream, in order

val close : t -> unit

Close the input stream. This is idempotent.

val copy_into : ?buf:bytes -> t -> Out.t -> unit

Copy the whole stream into the given output.

val map_char : (char -> char) -> t -> t

Transform the stream byte by byte

diff --git a/iostream/Iostream/In_buf/class-bufferized/index.html b/iostream/Iostream/In_buf/class-bufferized/index.html new file mode 100644 index 00000000..6bcc46ad --- /dev/null +++ b/iostream/Iostream/In_buf/class-bufferized/index.html @@ -0,0 +1,2 @@ + +bufferized (iostream.Iostream.In_buf.bufferized)

Class In_buf.bufferized

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/iostream/Iostream/In_buf/class-of_bytes/index.html b/iostream/Iostream/In_buf/class-of_bytes/index.html new file mode 100644 index 00000000..920aa9bc --- /dev/null +++ b/iostream/Iostream/In_buf/class-of_bytes/index.html @@ -0,0 +1,2 @@ + +of_bytes (iostream.Iostream.In_buf.of_bytes)

Class In_buf.of_bytes

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/iostream/Iostream/In_buf/class-of_in_channel/index.html b/iostream/Iostream/In_buf/class-of_in_channel/index.html new file mode 100644 index 00000000..e3c5fa4f --- /dev/null +++ b/iostream/Iostream/In_buf/class-of_in_channel/index.html @@ -0,0 +1,2 @@ + +of_in_channel (iostream.Iostream.In_buf.of_in_channel)

Class In_buf.of_in_channel

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/iostream/Iostream/In_buf/class-of_string/index.html b/iostream/Iostream/In_buf/class-of_string/index.html new file mode 100644 index 00000000..3ce5996d --- /dev/null +++ b/iostream/Iostream/In_buf/class-of_string/index.html @@ -0,0 +1,2 @@ + +of_string (iostream.Iostream.In_buf.of_string)

Class In_buf.of_string

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/iostream/Iostream/In_buf/class-open_file/index.html b/iostream/Iostream/In_buf/class-open_file/index.html new file mode 100644 index 00000000..86412cec --- /dev/null +++ b/iostream/Iostream/In_buf/class-open_file/index.html @@ -0,0 +1,2 @@ + +open_file (iostream.Iostream.In_buf.open_file)

Class In_buf.open_file

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/iostream/Iostream/In_buf/class-t_from_refill/index.html b/iostream/Iostream/In_buf/class-t_from_refill/index.html new file mode 100644 index 00000000..fc434bfa --- /dev/null +++ b/iostream/Iostream/In_buf/class-t_from_refill/index.html @@ -0,0 +1,2 @@ + +t_from_refill (iostream.Iostream.In_buf.t_from_refill)

Class In_buf.t_from_refill

A mixin to implement a buffered input by only providing a refill method. Add a close method and it's good to go.

method private virtual refill : Iostream__.Slice.t -> unit

Implementation of the stream: this takes a slice, resets its offset, and fills it with bytes. It must write at least one byte in the slice, unless the underlying input has reached its end.

method input : bytes -> int -> int -> int
method fill_buf : unit -> Iostream__.Slice.t
method consume : int -> unit
diff --git a/iostream/Iostream/In_buf/class-type-t/index.html b/iostream/Iostream/In_buf/class-type-t/index.html new file mode 100644 index 00000000..ceb69d44 --- /dev/null +++ b/iostream/Iostream/In_buf/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (iostream.Iostream.In_buf.t)

Class type In_buf.t

The implementation of buffered input streams.

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/iostream/Iostream/In_buf/index.html b/iostream/Iostream/In_buf/index.html new file mode 100644 index 00000000..dee917c7 --- /dev/null +++ b/iostream/Iostream/In_buf/index.html @@ -0,0 +1,18 @@ + +In_buf (iostream.Iostream.In_buf)

Module Iostream.In_buf

Buffered input stream.

class type t = object ... end

The implementation of buffered input streams.

class virtual t_from_refill : ?bytes:bytes -> unit -> object ... end

A mixin to implement a buffered input by only providing a refill method. Add a close method and it's good to go.

val create : + ?bytes:bytes -> + ?close:(unit -> unit) -> + refill:(bytes -> int) -> + unit -> + t

Create a new buffered input stream.

  • parameter refill

    will be called to refill the content of the bytes, returning how many bytes were added (starting at offset 0).

  • parameter buf

    the underlying buffer

  • raises Invalid_argument

    if the buffer's length is not at least 16.

class of_bytes : ?off:int -> ?len:int -> bytes -> t
val of_bytes : ?off:int -> ?len:int -> bytes -> t
class of_string : ?off:int -> ?len:int -> string -> t
val of_string : ?off:int -> ?len:int -> string -> t
class bufferized : ?bytes:bytes -> In.t -> t
val bufferized : ?bytes:bytes -> In.t -> t

Read from the given buffer.

class of_in_channel : ?bytes:bytes -> in_channel -> t
val of_in_channel : ?bytes:bytes -> in_channel -> t

Wrap a standard input channel.

class open_file : ?bytes:bytes -> ?mode:int -> ?flags:open_flag list -> string -> t
val open_file : + ?bytes:bytes -> + ?mode:int -> + ?flags:open_flag list -> + string -> + t
val with_open_file : + ?bytes:bytes -> + ?mode:int -> + ?flags:open_flag list -> + string -> + (t -> 'a) -> + 'a
val fill_buf : t -> Slice.t

fill_buffer bic returns a slice into bic's internal buffer, and ensures it's empty only if bic.ic is empty.

val input : t -> bytes -> int -> int -> int

Read into the given slice of bytes.

val of_in : ?bytes:bytes -> In.t -> t

Make a buffered version of the input stream.

  • parameter bytes

    the buffer to use.

  • raises Invalid_argument

    if the buffer's length is not at least 16.

val consume : t -> int -> unit

consume bic n consumes n bytes from bic. Precondition: n <= get_len bic, ie. one cannot consume bytes that have not yet been obtained via fill_buffer or fill_and_get.

val close : t -> unit

Close the input stream.

val into_in : t -> In.t

Cast into a In.t. This doesn't allocate.

val input_all_into_buffer : t -> Stdlib.Buffer.t -> unit

Read the whole content into the given buffer.

val input_all : ?buf:bytes -> t -> string

input_all ic reads the whole content of ic into a string.

  • parameter buf

    the initial buffer to use internally.

  • since 0.2
val copy_into : t -> Out.t -> unit

Copy the entire stream into the given output.

val skip : t -> int -> unit

skip ic n reads and dicards the next n bytes in ic.

val input_line : ?buffer:Stdlib.Buffer.t -> t -> string option

Read a line from the input. Return None if the stream is empty.

  • parameter buffer

    a buffer to use to hold the line.

val input_lines : ?buffer:Stdlib.Buffer.t -> t -> string list

Read all lines from the input.

val to_iter : t -> (char -> unit) -> unit
val to_seq : t -> char Stdlib.Seq.t
val of_seq : ?bytes:bytes -> char Stdlib.Seq.t -> t
diff --git a/iostream/Iostream/Out/class-dummy/index.html b/iostream/Iostream/Out/class-dummy/index.html new file mode 100644 index 00000000..fa033a9b --- /dev/null +++ b/iostream/Iostream/Out/class-dummy/index.html @@ -0,0 +1,2 @@ + +dummy (iostream.Iostream.Out.dummy)

Class Out.dummy

method output : bytes -> int -> int -> unit

Output slice

method close : unit -> unit

Close the output. Must be idempotent.

diff --git a/iostream/Iostream/Out/class-map_char/index.html b/iostream/Iostream/Out/class-map_char/index.html new file mode 100644 index 00000000..663eb157 --- /dev/null +++ b/iostream/Iostream/Out/class-map_char/index.html @@ -0,0 +1,2 @@ + +map_char (iostream.Iostream.Out.map_char)

Class Out.map_char

method output : bytes -> int -> int -> unit

Output slice

method close : unit -> unit

Close the output. Must be idempotent.

diff --git a/iostream/Iostream/Out/class-of_buffer/index.html b/iostream/Iostream/Out/class-of_buffer/index.html new file mode 100644 index 00000000..656e86ec --- /dev/null +++ b/iostream/Iostream/Out/class-of_buffer/index.html @@ -0,0 +1,2 @@ + +of_buffer (iostream.Iostream.Out.of_buffer)

Class Out.of_buffer

method output : bytes -> int -> int -> unit

Output slice

method close : unit -> unit

Close the output. Must be idempotent.

diff --git a/iostream/Iostream/Out/class-of_out_channel/index.html b/iostream/Iostream/Out/class-of_out_channel/index.html new file mode 100644 index 00000000..86701d5c --- /dev/null +++ b/iostream/Iostream/Out/class-of_out_channel/index.html @@ -0,0 +1,2 @@ + +of_out_channel (iostream.Iostream.Out.of_out_channel)

Class Out.of_out_channel

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/Out/class-type-t/index.html b/iostream/Iostream/Out/class-type-t/index.html new file mode 100644 index 00000000..2a8b9fa0 --- /dev/null +++ b/iostream/Iostream/Out/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (iostream.Iostream.Out.t)

Class type Out.t

An output stream, ie. a place into which we can write bytes. This can be a Buffer.t, an out_channel, a Unix.file_descr, etc.

method output : bytes -> int -> int -> unit

Output slice

method close : unit -> unit

Close the output. Must be idempotent.

diff --git a/iostream/Iostream/Out/class-type-t_seekable/index.html b/iostream/Iostream/Out/class-type-t_seekable/index.html new file mode 100644 index 00000000..688368b6 --- /dev/null +++ b/iostream/Iostream/Out/class-type-t_seekable/index.html @@ -0,0 +1,2 @@ + +t_seekable (iostream.Iostream.Out.t_seekable)

Class type Out.t_seekable

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/Out/index.html b/iostream/Iostream/Out/index.html new file mode 100644 index 00000000..92280b06 --- /dev/null +++ b/iostream/Iostream/Out/index.html @@ -0,0 +1,13 @@ + +Out (iostream.Iostream.Out)

Module Iostream.Out

Output stream.

class type t = object ... end

An output stream, ie. a place into which we can write bytes. This can be a Buffer.t, an out_channel, a Unix.file_descr, etc.

class type t_seekable = object ... end
class dummy : t
val dummy : t

Dummy output, drops everything written to it.

class of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable
val of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable

Wrap an out channel.

val of_buffer : Stdlib.Buffer.t -> t

of_buffer buf is an output channel that writes directly into buf. flush and close have no effect.

val open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + t_seekable

open_file file creates an out stream writing into the given file.

  • parameter mode

    permissions for the file creation

  • parameter flags

    set of unix flags to use. It must contain write permissions.

val with_open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + (t_seekable -> 'a) -> + 'a
val output : t -> bytes -> int -> int -> unit

Write the slice of bytes.

val close : t -> unit

Close the stream. Idempotent.

val output_string : t -> string -> unit

Output the whole string.

val output_int : t -> int -> unit

Output an integer in decimal notation.

val tee : t list -> t

tee ocs is an output that accepts bytes and writes them to every output in ocs. When closed, it closes all elements of oc.

class map_char : (char -> char) -> t -> t
val map_char : (char -> char) -> t -> t

Transform the stream byte by byte

diff --git a/iostream/Iostream/Out_buf/class-bufferized/index.html b/iostream/Iostream/Out_buf/class-bufferized/index.html new file mode 100644 index 00000000..f6b0ce1e --- /dev/null +++ b/iostream/Iostream/Out_buf/class-bufferized/index.html @@ -0,0 +1,2 @@ + +bufferized (iostream.Iostream.Out_buf.bufferized)

Class Out_buf.bufferized

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/iostream/Iostream/Out_buf/class-dummy/index.html b/iostream/Iostream/Out_buf/class-dummy/index.html new file mode 100644 index 00000000..3347e726 --- /dev/null +++ b/iostream/Iostream/Out_buf/class-dummy/index.html @@ -0,0 +1,2 @@ + +dummy (iostream.Iostream.Out_buf.dummy)

Class Out_buf.dummy

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/iostream/Iostream/Out_buf/class-of_buffer/index.html b/iostream/Iostream/Out_buf/class-of_buffer/index.html new file mode 100644 index 00000000..d8f80279 --- /dev/null +++ b/iostream/Iostream/Out_buf/class-of_buffer/index.html @@ -0,0 +1,2 @@ + +of_buffer (iostream.Iostream.Out_buf.of_buffer)

Class Out_buf.of_buffer

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/iostream/Iostream/Out_buf/class-of_out_channel/index.html b/iostream/Iostream/Out_buf/class-of_out_channel/index.html new file mode 100644 index 00000000..779dc111 --- /dev/null +++ b/iostream/Iostream/Out_buf/class-of_out_channel/index.html @@ -0,0 +1,2 @@ + +of_out_channel (iostream.Iostream.Out_buf.of_out_channel)

Class Out_buf.of_out_channel

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/Out_buf/class-open_file/index.html b/iostream/Iostream/Out_buf/class-open_file/index.html new file mode 100644 index 00000000..2e71541c --- /dev/null +++ b/iostream/Iostream/Out_buf/class-open_file/index.html @@ -0,0 +1,2 @@ + +open_file (iostream.Iostream.Out_buf.open_file)

Class Out_buf.open_file

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/Out_buf/class-t_from_output/index.html b/iostream/Iostream/Out_buf/class-t_from_output/index.html new file mode 100644 index 00000000..09883a98 --- /dev/null +++ b/iostream/Iostream/Out_buf/class-t_from_output/index.html @@ -0,0 +1,2 @@ + +t_from_output (iostream.Iostream.Out_buf.t_from_output)

Class Out_buf.t_from_output

Make a bufferized output from a non bufferized output+close.

inherit t
method private virtual output_underlying : bytes -> int -> int -> unit

Emit these private bytes, unbufferized

method private virtual close_underlying : unit -> unit

Close the underlying output. The bufferized output will flush and then call this.

diff --git a/iostream/Iostream/Out_buf/class-type-t/index.html b/iostream/Iostream/Out_buf/class-type-t/index.html new file mode 100644 index 00000000..9b68854b --- /dev/null +++ b/iostream/Iostream/Out_buf/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (iostream.Iostream.Out_buf.t)

Class type Out_buf.t

An output stream, ie. a place into which we can write bytes, with a buffer to amortize the cost of operations.

This can be a Buffer.t, an out_channel, a Unix.file_descr, etc.

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/iostream/Iostream/Out_buf/class-type-t_seekable/index.html b/iostream/Iostream/Out_buf/class-type-t_seekable/index.html new file mode 100644 index 00000000..1ef76e2b --- /dev/null +++ b/iostream/Iostream/Out_buf/class-type-t_seekable/index.html @@ -0,0 +1,2 @@ + +t_seekable (iostream.Iostream.Out_buf.t_seekable)

Class type Out_buf.t_seekable

inherit t
inherit Iostream__.Seekable.t
diff --git a/iostream/Iostream/Out_buf/index.html b/iostream/Iostream/Out_buf/index.html new file mode 100644 index 00000000..b961c63a --- /dev/null +++ b/iostream/Iostream/Out_buf/index.html @@ -0,0 +1,20 @@ + +Out_buf (iostream.Iostream.Out_buf)

Module Iostream.Out_buf

Buffered output stream.

class type t = object ... end

An output stream, ie. a place into which we can write bytes, with a buffer to amortize the cost of operations.

class type t_seekable = object ... end
val create : + ?flush:(unit -> unit) -> + ?close:(unit -> unit) -> + output_char:(char -> unit) -> + output:(bytes -> int -> int -> unit) -> + unit -> + t

Create a new output stream from raw components.

class dummy : t
val dummy : t

Dummy output, drops everything written to it.

class virtual t_from_output : ?bytes:bytes -> unit -> object ... end

Make a bufferized output from a non bufferized output+close.

class bufferized : ?bytes:bytes -> Out.t -> t
val bufferized : ?bytes:bytes -> Out.t -> t
class of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable
val of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable

Wrap an out channel.

val of_buffer : Stdlib.Buffer.t -> t

of_buffer buf is an output channel that writes directly into buf. flush and close have no effect.

class open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string -> + t_seekable
val open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + t_seekable

open_file file creates an out stream writing into the given file.

  • parameter mode

    permissions for the file creation

  • parameter flags

    set of unix flags to use. It must contain write permissions.

val with_open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + (t_seekable -> 'a) -> + 'a
val output_char : t -> char -> unit

Output a single char

val output : t -> bytes -> int -> int -> unit

Write the slice of bytes.

val close : t -> unit

Close the stream. Idempotent.

val flush : t -> unit

Ensure the bytes written so far are indeed written to the underlying storage/network socket/… and are not just sitting in a buffer.

val output_string : t -> string -> unit

Output the whole string.

val output_line : t -> string -> unit

Output the whole string followed by '\n'.

  • since 0.2
val output_lines : t -> string Stdlib.Seq.t -> unit

Output a series of lines, each terminated by '\n'.

val output_int : t -> int -> unit

Output an integer in decimal notation.

val tee : t list -> t

tee ocs is an output that accepts bytes and writes them to every output in ocs. When closed, it closes all elements of oc.

val map_char : (char -> char) -> t -> t

Transform the stream byte by byte

diff --git a/iostream/Iostream/Seekable/class-type-t/index.html b/iostream/Iostream/Seekable/class-type-t/index.html new file mode 100644 index 00000000..73f1b662 --- /dev/null +++ b/iostream/Iostream/Seekable/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (iostream.Iostream.Seekable.t)

Class type Seekable.t

method seek : int -> unit

Seek in the underlying stream.

  • raises Sys_error

    in case of failure

method pos : unit -> int

Return current offset in underlying stream.

  • raises Sys_error

    in case of failure

diff --git a/iostream/Iostream/Seekable/index.html b/iostream/Iostream/Seekable/index.html new file mode 100644 index 00000000..a67461b9 --- /dev/null +++ b/iostream/Iostream/Seekable/index.html @@ -0,0 +1,2 @@ + +Seekable (iostream.Iostream.Seekable)

Module Iostream.Seekable

An object we can seek in.

Files can be seeked in, i.e the read/write head can move around.

class type t = object ... end
val seek : t -> int -> unit
val pos : t -> int
diff --git a/iostream/Iostream/Slice/index.html b/iostream/Iostream/Slice/index.html new file mode 100644 index 00000000..39f36b98 --- /dev/null +++ b/iostream/Iostream/Slice/index.html @@ -0,0 +1,2 @@ + +Slice (iostream.Iostream.Slice)

Module Iostream.Slice

Byte slice or buffer.

type t = {
  1. bytes : bytes;
    (*

    Bytes

    *)
  2. mutable off : int;
    (*

    Offset in bytes

    *)
  3. mutable len : int;
    (*

    Length of the slice. Empty slice has len=0

    *)
}

A slice of bytes. The valid bytes in the slice are bytes[off], bytes[off+1], …, bytes[off+len-1] (i.e len bytes starting at offset off).

val empty : t
val create : int -> t
val of_bytes : bytes -> t
val bytes : t -> bytes
val off : t -> int
val len : t -> int
val consume : t -> int -> unit

Consume the first n bytes from the slice, making it n bytes shorter. This modifies the slice in place.

val find_index_exn : t -> char -> int

find index of c in slice, or raise Not_found

diff --git a/iostream/Iostream/index.html b/iostream/Iostream/index.html new file mode 100644 index 00000000..8475e556 --- /dev/null +++ b/iostream/Iostream/index.html @@ -0,0 +1,2 @@ + +Iostream (iostream.Iostream)

Module Iostream

I/O streams.

This module defines generic I/O streams. They can be user-defined and can be composed from other streams.

module In : sig ... end

Input stream.

module In_buf : sig ... end

Buffered input stream.

module Out : sig ... end

Output stream.

module Out_buf : sig ... end

Buffered output stream.

module Slice : sig ... end

Byte slice or buffer.

module Seekable : sig ... end

An object we can seek in.

diff --git a/iostream/Iostream__/index.html b/iostream/Iostream__/index.html new file mode 100644 index 00000000..49dba734 --- /dev/null +++ b/iostream/Iostream__/index.html @@ -0,0 +1,2 @@ + +Iostream__ (iostream.Iostream__)

Module Iostream__

This module is hidden.

diff --git a/iostream/Iostream__In/index.html b/iostream/Iostream__In/index.html new file mode 100644 index 00000000..1235b986 --- /dev/null +++ b/iostream/Iostream__In/index.html @@ -0,0 +1,2 @@ + +Iostream__In (iostream.Iostream__In)

Module Iostream__In

This module is hidden.

diff --git a/iostream/Iostream__In_buf/index.html b/iostream/Iostream__In_buf/index.html new file mode 100644 index 00000000..d0bf5e07 --- /dev/null +++ b/iostream/Iostream__In_buf/index.html @@ -0,0 +1,2 @@ + +Iostream__In_buf (iostream.Iostream__In_buf)

Module Iostream__In_buf

This module is hidden.

diff --git a/iostream/Iostream__Out/index.html b/iostream/Iostream__Out/index.html new file mode 100644 index 00000000..ab9af200 --- /dev/null +++ b/iostream/Iostream__Out/index.html @@ -0,0 +1,2 @@ + +Iostream__Out (iostream.Iostream__Out)

Module Iostream__Out

This module is hidden.

diff --git a/iostream/Iostream__Out_buf/index.html b/iostream/Iostream__Out_buf/index.html new file mode 100644 index 00000000..ed0b9de1 --- /dev/null +++ b/iostream/Iostream__Out_buf/index.html @@ -0,0 +1,2 @@ + +Iostream__Out_buf (iostream.Iostream__Out_buf)

Module Iostream__Out_buf

This module is hidden.

diff --git a/iostream/Iostream__Seekable/index.html b/iostream/Iostream__Seekable/index.html new file mode 100644 index 00000000..927180dd --- /dev/null +++ b/iostream/Iostream__Seekable/index.html @@ -0,0 +1,2 @@ + +Iostream__Seekable (iostream.Iostream__Seekable)

Module Iostream__Seekable

This module is hidden.

diff --git a/iostream/Iostream__Slice/index.html b/iostream/Iostream__Slice/index.html new file mode 100644 index 00000000..8ab5cc0b --- /dev/null +++ b/iostream/Iostream__Slice/index.html @@ -0,0 +1,2 @@ + +Iostream__Slice (iostream.Iostream__Slice)

Module Iostream__Slice

This module is hidden.

diff --git a/iostream/Iostream_unix/In/index.html b/iostream/Iostream_unix/In/index.html new file mode 100644 index 00000000..0e80a32c --- /dev/null +++ b/iostream/Iostream_unix/In/index.html @@ -0,0 +1,2 @@ + +In (iostream.Iostream_unix.In)

Module Iostream_unix.In

val of_unix_fd : ?close_noerr:bool -> Unix.file_descr -> Iostream.In.t_seekable

Create an in stream from a raw Unix file descriptor. The file descriptor must be opened for reading.

diff --git a/iostream/Iostream_unix/Out/index.html b/iostream/Iostream_unix/Out/index.html new file mode 100644 index 00000000..00828e0d --- /dev/null +++ b/iostream/Iostream_unix/Out/index.html @@ -0,0 +1,2 @@ + +Out (iostream.Iostream_unix.Out)

Module Iostream_unix.Out

Output stream directly writing into the given Unix file descriptor.

diff --git a/iostream/Iostream_unix/index.html b/iostream/Iostream_unix/index.html new file mode 100644 index 00000000..96549708 --- /dev/null +++ b/iostream/Iostream_unix/index.html @@ -0,0 +1,2 @@ + +Iostream_unix (iostream.Iostream_unix)

Module Iostream_unix

module In : sig ... end
module Out : sig ... end
diff --git a/iostream/_doc-dir/CHANGES.md b/iostream/_doc-dir/CHANGES.md new file mode 100644 index 00000000..f4e17a1c --- /dev/null +++ b/iostream/_doc-dir/CHANGES.md @@ -0,0 +1,15 @@ + +# 0.2 + +- camlzip: add buffered version of the input stream transducers +- add In_buf.skip +- add `iostream-camlzip`, depends on `iostream` +- rename Out to Out_buf, add Out +- add `Slice` type, used for buffered input +- add `iostream.unix` optional library +- split seekable into its own class +- breaking: use OO and `class type` for all types + +# 0.1 + +initial release diff --git a/iostream/_doc-dir/README.md b/iostream/_doc-dir/README.md new file mode 100644 index 00000000..32e92535 --- /dev/null +++ b/iostream/_doc-dir/README.md @@ -0,0 +1,20 @@ +# Iostream + +[![Build and Test](https://github.com/c-cube/ocaml-iostream/actions/workflows/main.yml/badge.svg)](https://github.com/c-cube/ocaml-iostream/actions/workflows/main.yml) + +This library defines _generic_ I/O streams of bytes. The streams should be +composable, user-definable, and agnostic to the underlying I/O mechanism; with +OCaml 5 it means that they might be backed by an effect-based scheduler. + +The goal is to provide a reasonable interoperability layer that multiple libraries and applications +in the OCaml ecosystem can rely on, while providing the modularity that standard IO channels lack. +Modern statically typed languages like Go and Rust provide this layer in their stdlib and their whole +ecosystem can build on it. + +## Documentation + +https://c-cube.github.io/ocaml-iostream/ + +## License + +MIT license. diff --git a/iostream/index.html b/iostream/index.html new file mode 100644 index 00000000..ffd929dc --- /dev/null +++ b/iostream/index.html @@ -0,0 +1,2 @@ + +index (iostream.index)

Package iostream

Package info

changes-files
readme-files
diff --git a/tiny_httpd/Tiny_httpd/index.html b/tiny_httpd/Tiny_httpd/index.html index ed02f451..0c87bac0 100644 --- a/tiny_httpd/Tiny_httpd/index.html +++ b/tiny_httpd/Tiny_httpd/index.html @@ -49,7 +49,69 @@ echo: Accept: */* Content-Length: 10 Content-Type: application/x-www-form-urlencoded; - path="/echo"; body="howdy y'all"}

Tiny buffer implementation

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

module Buf = Tiny_httpd_buf

Generic byte streams

module Byte_stream = Tiny_httpd_stream

IO Abstraction

module IO = Tiny_httpd_io

Logging

module Log = Tiny_httpd_log

Main Server Type

type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t
HTTP Methods
Headers

Headers are metadata associated with a request or response.

module Headers = Tiny_httpd_server.Headers
Requests

Requests are sent by a client, e.g. a web browser or cURL. From the point of view of the server, they're inputs.

module Request = Tiny_httpd_server.Request
Response Codes
module Response_code = Tiny_httpd_server.Response_code
Responses

Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t

module Response = Tiny_httpd_server.Response
Routing

Basic type-safe routing of handlers based on URL paths. This is optional, it is possible to only define the root handler with something like Routes.

Middlewares

A middleware can be inserted in a handler to modify or observe its behavior.

module Middleware = Tiny_httpd_server.Middleware
Main Server type

A HTTP server. See create for more details.

val create : + path="/echo"; body="howdy y'all"}

Tiny buffer implementation

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

module Buf = Tiny_httpd_core.Buf

IO Abstraction

module IO = Tiny_httpd_core.IO

Logging

module Log = Tiny_httpd_core.Log

Utils

module Util = Tiny_httpd_core.Util

Resource pool

module Pool = Tiny_httpd_core.Pool

Static directory serving

module Dir = Tiny_httpd_unix.Dir
module type VFS = Tiny_httpd_unix.Dir.VFS

HTML combinators

module Html = Tiny_httpd_html

Main server types

module Request = Tiny_httpd_core.Request
module Response = Tiny_httpd_core.Response
module Response_code = Tiny_httpd_core.Response_code
module Route = Tiny_httpd_core.Route
module Headers = Tiny_httpd_core.Headers
module Meth = Tiny_httpd_core.Meth
module Server = Tiny_httpd_core.Server
Middlewares

A middleware can be inserted in a handler to modify or observe its behavior.

  • since 0.11
module Middleware = Server.Middleware
Main Server type

A HTTP server. See create for more details.

module type IO_BACKEND = Server.IO_BACKEND

A backend that provides IO operations, network operations, etc.

val create_from : + ?buf_size:int -> + ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> + backend:(module IO_BACKEND) -> + unit -> + t

Create a new webserver using provided backend.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter buf_size

    size for buffers (since 0.11)

  • since 0.14
val addr : t -> string

Address on which the server listens.

val is_ipv6 : t -> bool

is_ipv6 server returns true iff the address of the server is an IPv6 address.

  • since 0.3
val port : t -> int

Port on which the server listens. Note that this might be different than the port initially given if the port was 0 (meaning that the OS picks a port for us).

val active_connections : t -> int

Number of currently active connections.

val add_decode_request_cb : + t -> + (unit Tiny_httpd_core.Request.t -> + (unit Tiny_httpd_core.Request.t + * (Tiny_httpd_core.IO.Input.t -> + Tiny_httpd_core.IO.Input.t)) + option) -> + unit

Add a callback for every request. The callback can provide a stream transformer and a new request (with modified headers, typically). A possible use is to handle decompression by looking for a Transfer-Encoding header and returning a stream transformer that decompresses on the fly.

val add_encode_response_cb : + t -> + (unit Tiny_httpd_core.Request.t -> + Tiny_httpd_core.Response.t -> + Tiny_httpd_core.Response.t option) -> + unit

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. The callback is given the query with only its headers, as well as the current response.

val add_middleware : + stage:[ `Encoding | `Stage of int ] -> + t -> + Middleware.t -> + unit

Add a middleware to every request/response pair.

  • parameter stage

    specify when middleware applies. Encoding comes first (outermost layer), then stages in increasing order.

  • raises Invalid_argument

    if stage is `Stage n where n < 1

  • since 0.11
Request handlers

Setup a handler called by default.

This handler is called with any request not accepted by any handler installed via add_path_handler. 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 0.14 . Use Request.read_body_full to read the body into a string if needed.

val add_route_handler : + ?accept: + (unit Tiny_httpd_core.Request.t -> + (unit, Tiny_httpd_core.Response_code.t * string) result) -> + ?middlewares:Middleware.t list -> + ?meth:Tiny_httpd_core.Meth.t -> + t -> + ('a, string Tiny_httpd_core.Request.t -> Tiny_httpd_core.Response.t) + Tiny_httpd_core.Route.t -> + 'a -> + unit

add_route_handler server Route.(exact "path" @/ string @/ int @/ return) f calls f "foo" 42 request when a request with path "path/foo/42/" is received.

Note that the handlers are called in the reverse order of their addition, so the last registered handler can override previously registered ones.

  • parameter meth

    if provided, only accept requests with the given method. Typically one could react to `GET or `PUT.

  • parameter accept

    should return Ok() if the given request (before its body is read) should be accepted, Error (code,message) if it's to be rejected (e.g. because its content is too big, or for some permission error). See the http_of_dir program for an example of how to use accept to filter uploads that are too large before the upload even starts. The default always returns Ok(), i.e. it accepts all requests.

  • since 0.6
val add_route_handler_stream : + ?accept: + (unit Tiny_httpd_core.Request.t -> + (unit, Tiny_httpd_core.Response_code.t * string) result) -> + ?middlewares:Middleware.t list -> + ?meth:Tiny_httpd_core.Meth.t -> + t -> + ('a, + Tiny_httpd_core.IO.Input.t Tiny_httpd_core.Request.t -> + Tiny_httpd_core.Response.t) + Tiny_httpd_core.Route.t -> + 'a -> + unit

Similar to add_route_handler, but where the body of the request is a stream of bytes that has not been read yet. This is useful when one wants to stream the body directly into a parser, json decoder (such as Jsonm) or into a file.

  • since 0.6
Server-sent events

EXPERIMENTAL: this API is not stable yet.

module type SERVER_SENT_GENERATOR = Server.SERVER_SENT_GENERATOR

A server-side function to generate of Server-sent events.

type server_sent_generator = (module SERVER_SENT_GENERATOR)

Server-sent event generator. This generates events that are forwarded to the client (e.g. the browser).

  • since 0.9
val add_route_server_sent_handler : + ?accept: + (unit Tiny_httpd_core.Request.t -> + (unit, Tiny_httpd_core.Response_code.t * string) result) -> + t -> + ('a, string Tiny_httpd_core.Request.t -> server_sent_generator -> unit) + Tiny_httpd_core.Route.t -> + 'a -> + unit

Add a handler on an endpoint, that serves server-sent events.

The callback is given a generator that can be used to send events as it pleases. The connection is always closed by the client, and the accepted method is always GET. This will set the header "content-type" to "text/event-stream" automatically and reply with a 200 immediately. See server_sent_generator for more details.

This handler stays on the original thread (it is synchronous).

  • since 0.9
Upgrade handlers

These handlers upgrade the connection to another protocol.

  • since NEXT_RELEASE
module type UPGRADE_HANDLER = Server.UPGRADE_HANDLER

Handler that upgrades to another protocol.

type upgrade_handler = (module UPGRADE_HANDLER)
  • since NEXT_RELEASE
val add_upgrade_handler : + ?accept: + (unit Tiny_httpd_core.Request.t -> + (unit, Tiny_httpd_core.Response_code.t * string) result) -> + t -> + ('a, upgrade_handler) Tiny_httpd_core.Route.t -> + 'a -> + unit
Run the server
val running : t -> bool

Is the server running?

  • since 0.14
val stop : t -> unit

Ask the server to stop. This might not have an immediate effect as run might currently be waiting on IO.

val run : ?after_init:(unit -> unit) -> t -> (unit, exn) result

Run the main loop of the server, listening on a socket described at the server's creation time, using new_thread to start a thread for each new client.

This returns Ok () if the server exits gracefully, or Error e if it exits with an error.

  • parameter after_init

    is called after the server starts listening. since 0.13 .

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 0.14
val create : ?masksigpipe:bool -> ?max_connections:int -> ?timeout:float -> @@ -59,45 +121,6 @@ echo: ?addr:string -> ?port:int -> ?sock:Unix.file_descr -> - ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> + ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> unit -> - t

Create a new webserver using UNIX abstractions.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter masksigpipe

    if true, block the signal Sys.sigpipe which otherwise tends to kill client threads when they try to write on broken sockets. Default: true.

  • parameter buf_size

    size for buffers (since 0.11)

  • parameter new_thread

    a function used to spawn a new thread to handle a new client connection. By default it is Thread.create but one could use a thread pool instead. See for example this use of moonpool.

  • parameter max_connections

    maximum number of simultaneous connections.

  • parameter timeout

    connection is closed if the socket does not do read or write for the amount of second. Default: 0.0 which means no timeout. timeout is not recommended when using proxy.

  • parameter addr

    address (IPv4 or IPv6) to listen on. Default "127.0.0.1".

  • parameter port

    to listen on. Default 8080.

  • parameter sock

    an existing socket given to the server to listen on, e.g. by systemd on Linux (or launchd on macOS). If passed in, this socket will be used instead of the addr and port. If not passed in, those will be used. This parameter exists since 0.10.

  • parameter get_time_s

    obtain the current timestamp in seconds. This parameter exists since 0.11.

module type IO_BACKEND = Tiny_httpd_server.IO_BACKEND

A backend that provides IO operations, network operations, etc.

val create_from : - ?buf_size:int -> - ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> - backend:(module IO_BACKEND) -> - unit -> - t

Create a new webserver using provided backend.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter buf_size

    size for buffers (since 0.11)

  • since 0.14
val addr : t -> string

Address on which the server listens.

val is_ipv6 : t -> bool

is_ipv6 server returns true iff the address of the server is an IPv6 address.

  • since 0.3
val port : t -> int

Port on which the server listens. Note that this might be different than the port initially given if the port was 0 (meaning that the OS picks a port for us).

val active_connections : t -> int

Number of currently active connections.

val add_decode_request_cb : - t -> - (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> - unit

Add a callback for every request. The callback can provide a stream transformer and a new request (with modified headers, typically). A possible use is to handle decompression by looking for a Transfer-Encoding header and returning a stream transformer that decompresses on the fly.

val add_encode_response_cb : - t -> - (unit Request.t -> Response.t -> Response.t option) -> - unit

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. The callback is given the query with only its headers, as well as the current response.

val add_middleware : - stage:[ `Encoding | `Stage of int ] -> - t -> - Middleware.t -> - unit

Add a middleware to every request/response pair.

  • parameter stage

    specify when middleware applies. Encoding comes first (outermost layer), then stages in increasing order.

  • raises Invalid_argument

    if stage is `Stage n where n < 1

  • since 0.11
Request handlers
val set_top_handler : t -> (byte_stream Request.t -> Response.t) -> unit

Setup a handler called by default.

This handler is called with any request not accepted by any handler installed via add_path_handler. 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 0.14 . Use Request.read_body_full to read the body into a string if needed.

val add_route_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - ?middlewares:Middleware.t list -> - ?meth:Meth.t -> - t -> - ('a, string Request.t -> Response.t) Route.t -> - 'a -> - unit

add_route_handler server Route.(exact "path" @/ string @/ int @/ return) f calls f "foo" 42 request when a request with path "path/foo/42/" is received.

Note that the handlers are called in the reverse order of their addition, so the last registered handler can override previously registered ones.

  • parameter meth

    if provided, only accept requests with the given method. Typically one could react to `GET or `PUT.

  • parameter accept

    should return Ok() if the given request (before its body is read) should be accepted, Error (code,message) if it's to be rejected (e.g. because its content is too big, or for some permission error). See the http_of_dir program for an example of how to use accept to filter uploads that are too large before the upload even starts. The default always returns Ok(), i.e. it accepts all requests.

  • since 0.6
val add_route_handler_stream : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - ?middlewares:Middleware.t list -> - ?meth:Meth.t -> - t -> - ('a, byte_stream Request.t -> Response.t) Route.t -> - 'a -> - unit

Similar to add_route_handler, but where the body of the request is a stream of bytes that has not been read yet. This is useful when one wants to stream the body directly into a parser, json decoder (such as Jsonm) or into a file.

  • since 0.6
Server-sent events

EXPERIMENTAL: this API is not stable yet.

module type SERVER_SENT_GENERATOR = Tiny_httpd_server.SERVER_SENT_GENERATOR

A server-side function to generate of Server-sent events.

type server_sent_generator = (module SERVER_SENT_GENERATOR)

Server-sent event generator. This generates events that are forwarded to the client (e.g. the browser).

  • since 0.9
val add_route_server_sent_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - t -> - ('a, string Request.t -> server_sent_generator -> unit) Route.t -> - 'a -> - unit

Add a handler on an endpoint, that serves server-sent events.

The callback is given a generator that can be used to send events as it pleases. The connection is always closed by the client, and the accepted method is always GET. This will set the header "content-type" to "text/event-stream" automatically and reply with a 200 immediately. See server_sent_generator for more details.

This handler stays on the original thread (it is synchronous).

  • since 0.9
Upgrade handlers

These handlers upgrade the connection to another protocol.

  • since NEXT_RELEASE
module type UPGRADE_HANDLER = Tiny_httpd_server.UPGRADE_HANDLER

Handler that upgrades to another protocol.

type upgrade_handler = (module UPGRADE_HANDLER)
  • since NEXT_RELEASE
val add_upgrade_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - t -> - ('a, upgrade_handler) Route.t -> - 'a -> - unit
Run the server
val running : t -> bool

Is the server running?

  • since 0.14
val stop : t -> unit

Ask the server to stop. This might not have an immediate effect as run might currently be waiting on IO.

val run : ?after_init:(unit -> unit) -> t -> (unit, exn) result

Run the main loop of the server, listening on a socket described at the server's creation time, using new_thread to start a thread for each new client.

This returns Ok () if the server exits gracefully, or Error e if it exits with an error.

  • parameter after_init

    is called after the server starts listening. since 0.13 .

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 0.14

Utils

module Util = Tiny_httpd_util

Resource pool

module Pool = Tiny_httpd_pool

Static directory serving

module Dir = Tiny_httpd_dir
module Html = Tiny_httpd_html
+ t

Create a new webserver using UNIX abstractions.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter masksigpipe

    if true, block the signal Sys.sigpipe which otherwise tends to kill client threads when they try to write on broken sockets. Default: true.

  • parameter buf_size

    size for buffers (since 0.11)

  • parameter new_thread

    a function used to spawn a new thread to handle a new client connection. By default it is Thread.create but one could use a thread pool instead. See for example this use of moonpool.

  • parameter max_connections

    maximum number of simultaneous connections.

  • parameter timeout

    connection is closed if the socket does not do read or write for the amount of second. Default: 0.0 which means no timeout. timeout is not recommended when using proxy.

  • parameter addr

    address (IPv4 or IPv6) to listen on. Default "127.0.0.1".

  • parameter port

    to listen on. Default 8080.

  • parameter sock

    an existing socket given to the server to listen on, e.g. by systemd on Linux (or launchd on macOS). If passed in, this socket will be used instead of the addr and port. If not passed in, those will be used. This parameter exists since 0.10.

  • parameter get_time_s

    obtain the current timestamp in seconds. This parameter exists since 0.11.

diff --git a/tiny_httpd/Tiny_httpd_atomic_/index.html b/tiny_httpd/Tiny_httpd_atomic_/index.html deleted file mode 100644 index 791bed86..00000000 --- a/tiny_httpd/Tiny_httpd_atomic_/index.html +++ /dev/null @@ -1,64 +0,0 @@ - -Tiny_httpd_atomic_ (tiny_httpd.Tiny_httpd_atomic_)

Module Tiny_httpd_atomic_

include module type of struct include Stdlib.Atomic end
type !'a t = 'a Stdlib.Atomic.t

An atomic (mutable) reference to a value of type 'a.

val make : 'a -> 'a t

Create an atomic reference.

val get : 'a t -> 'a

Get the current value of the atomic reference.

val set : 'a t -> 'a -> unit

Set a new value for the atomic reference.

val exchange : 'a t -> 'a -> 'a

Set a new value for the atomic reference, and return the current value.

val compare_and_set : 'a t -> 'a -> 'a -> bool

compare_and_set r seen v sets the new value of r to v only if its current value is physically equal to seen -- the comparison and the set occur atomically. Returns true if the comparison succeeded (so the set happened) and false otherwise.

val fetch_and_add : int t -> int -> int

fetch_and_add r n atomically increments the value of r by n, and returns the current value (before the increment).

val incr : int t -> unit

incr r atomically increments the value of r by 1.

val decr : int t -> unit

decr r atomically decrements the value of r by 1.

Examples

Basic Thread Coordination

A basic use case is to have global counters that are updated in a thread-safe way, for example to keep some sorts of metrics over IOs performed by the program. Another basic use case is to coordinate the termination of threads in a given program, for example when one thread finds an answer, or when the program is shut down by the user.

Here, for example, we're going to try to find a number whose hash satisfies a basic property. To do that, we'll run multiple threads which will try random numbers until they find one that works.

Of course the output below is a sample run and will change every time the program is run.

(* use for termination *)
-let stop_all_threads = Atomic.make false
-
-(* total number of individual attempts to find a number *)
-let num_attempts = Atomic.make 0
-
-(* find a number that satisfies [p], by... trying random numbers
-   until one fits. *)
-let find_number_where (p:int -> bool) =
-  let rand = Random.State.make_self_init() in
-  while not (Atomic.get stop_all_threads) do
-
-    let n = Random.State.full_int rand max_int in
-    ignore (Atomic.fetch_and_add num_attempts 1 : int);
-
-    if p (Hashtbl.hash n) then (
-      Printf.printf "found %d (hash=%d)\n%!" n (Hashtbl.hash n);
-      Atomic.set stop_all_threads true; (* signal all threads to stop *)
-    )
-  done;;
-
-
-(* run multiple domains to search for a [n] where [hash n <= 100] *)
-let () =
-  let criterion n = n <= 100 in
-  let threads =
-    Array.init 8
-      (fun _ -> Domain.spawn (fun () -> find_number_where criterion))
-  in
-  Array.iter Domain.join threads;
-  Printf.printf "total number of attempts: %d\n%!"
-    (Atomic.get num_attempts) ;;
-
-- : unit = ()
-found 1651745641680046833 (hash=33)
-total number of attempts: 30230350

Treiber Stack

Another example is a basic Treiber stack (a thread-safe stack) that can be safely shared between threads.

Note how both push and pop are recursive, because they attempt to swap the new stack (with one more, or one fewer, element) with the old stack. This is optimistic concurrency: each iteration of, say, push stack x gets the old stack l, and hopes that by the time it tries to replace l with x::l, nobody else has had time to modify the list. If the compare_and_set fails it means we were too optimistic, and must try again.

type 'a stack = 'a list Atomic.t
-
-let rec push (stack: _ stack) elt : unit =
-  let cur = Atomic.get stack in
-  let success = Atomic.compare_and_set stack cur (elt :: cur) in
-  if not success then
-    push stack elt
-
-let rec pop (stack: _ stack) : _ option =
-  let cur = Atomic.get stack in
-  match cur with
-  | [] -> None
-  | x :: tail ->
-    let success = Atomic.compare_and_set stack cur tail in
-    if success then Some x
-    else pop stack
-
-# let st = Atomic.make []
-# push st 1
-- : unit = ()
-# push st 2
-- : unit = ()
-# pop st
-- : int option = Some 2
-# pop st
-- : int option = Some 1
-# pop st
-- : int option = None
diff --git a/tiny_httpd/Tiny_httpd_buf/index.html b/tiny_httpd/Tiny_httpd_buf/index.html deleted file mode 100644 index ab9271b9..00000000 --- a/tiny_httpd/Tiny_httpd_buf/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Tiny_httpd_buf (tiny_httpd.Tiny_httpd_buf)

Module Tiny_httpd_buf

Simple buffer.

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

type t
val size : t -> int
val clear : t -> unit
val create : ?size:int -> unit -> t
val contents : t -> string
val clear_and_zero : t -> unit

Clear the buffer and zero out its storage.

  • since 0.15
val bytes_slice : t -> bytes

Access underlying slice of bytes.

  • since 0.5
val contents_and_clear : t -> string

Get contents of the buffer and clear it.

  • since 0.5
val add_char : t -> char -> unit

Add a single char.

  • 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 0.14
val add_buffer : t -> Stdlib.Buffer.t -> unit

Append bytes from buffer.

  • since 0.14
diff --git a/tiny_httpd/Tiny_httpd_core/Atomic_/index.html b/tiny_httpd/Tiny_httpd_core/Atomic_/index.html new file mode 100644 index 00000000..c102dd90 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Atomic_/index.html @@ -0,0 +1,64 @@ + +Atomic_ (tiny_httpd.Tiny_httpd_core.Atomic_)

Module Tiny_httpd_core.Atomic_

include module type of struct include Stdlib.Atomic end
type !'a t = 'a Stdlib.Atomic.t

An atomic (mutable) reference to a value of type 'a.

val make : 'a -> 'a t

Create an atomic reference.

val get : 'a t -> 'a

Get the current value of the atomic reference.

val set : 'a t -> 'a -> unit

Set a new value for the atomic reference.

val exchange : 'a t -> 'a -> 'a

Set a new value for the atomic reference, and return the current value.

val compare_and_set : 'a t -> 'a -> 'a -> bool

compare_and_set r seen v sets the new value of r to v only if its current value is physically equal to seen -- the comparison and the set occur atomically. Returns true if the comparison succeeded (so the set happened) and false otherwise.

val fetch_and_add : int t -> int -> int

fetch_and_add r n atomically increments the value of r by n, and returns the current value (before the increment).

val incr : int t -> unit

incr r atomically increments the value of r by 1.

val decr : int t -> unit

decr r atomically decrements the value of r by 1.

Examples

Basic Thread Coordination

A basic use case is to have global counters that are updated in a thread-safe way, for example to keep some sorts of metrics over IOs performed by the program. Another basic use case is to coordinate the termination of threads in a given program, for example when one thread finds an answer, or when the program is shut down by the user.

Here, for example, we're going to try to find a number whose hash satisfies a basic property. To do that, we'll run multiple threads which will try random numbers until they find one that works.

Of course the output below is a sample run and will change every time the program is run.

(* use for termination *)
+let stop_all_threads = Atomic.make false
+
+(* total number of individual attempts to find a number *)
+let num_attempts = Atomic.make 0
+
+(* find a number that satisfies [p], by... trying random numbers
+   until one fits. *)
+let find_number_where (p:int -> bool) =
+  let rand = Random.State.make_self_init() in
+  while not (Atomic.get stop_all_threads) do
+
+    let n = Random.State.full_int rand max_int in
+    ignore (Atomic.fetch_and_add num_attempts 1 : int);
+
+    if p (Hashtbl.hash n) then (
+      Printf.printf "found %d (hash=%d)\n%!" n (Hashtbl.hash n);
+      Atomic.set stop_all_threads true; (* signal all threads to stop *)
+    )
+  done;;
+
+
+(* run multiple domains to search for a [n] where [hash n <= 100] *)
+let () =
+  let criterion n = n <= 100 in
+  let threads =
+    Array.init 8
+      (fun _ -> Domain.spawn (fun () -> find_number_where criterion))
+  in
+  Array.iter Domain.join threads;
+  Printf.printf "total number of attempts: %d\n%!"
+    (Atomic.get num_attempts) ;;
+
+- : unit = ()
+found 1651745641680046833 (hash=33)
+total number of attempts: 30230350

Treiber Stack

Another example is a basic Treiber stack (a thread-safe stack) that can be safely shared between threads.

Note how both push and pop are recursive, because they attempt to swap the new stack (with one more, or one fewer, element) with the old stack. This is optimistic concurrency: each iteration of, say, push stack x gets the old stack l, and hopes that by the time it tries to replace l with x::l, nobody else has had time to modify the list. If the compare_and_set fails it means we were too optimistic, and must try again.

type 'a stack = 'a list Atomic.t
+
+let rec push (stack: _ stack) elt : unit =
+  let cur = Atomic.get stack in
+  let success = Atomic.compare_and_set stack cur (elt :: cur) in
+  if not success then
+    push stack elt
+
+let rec pop (stack: _ stack) : _ option =
+  let cur = Atomic.get stack in
+  match cur with
+  | [] -> None
+  | x :: tail ->
+    let success = Atomic.compare_and_set stack cur tail in
+    if success then Some x
+    else pop stack
+
+# let st = Atomic.make []
+# push st 1
+- : unit = ()
+# push st 2
+- : unit = ()
+# pop st
+- : int option = Some 2
+# pop st
+- : int option = Some 1
+# pop st
+- : int option = None
diff --git a/tiny_httpd/Tiny_httpd_core/Buf/index.html b/tiny_httpd/Tiny_httpd_core/Buf/index.html new file mode 100644 index 00000000..94593ca2 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Buf/index.html @@ -0,0 +1,2 @@ + +Buf (tiny_httpd.Tiny_httpd_core.Buf)

Module Tiny_httpd_core.Buf

Simple buffer.

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

type t
val size : t -> int
val clear : t -> unit
val create : ?size:int -> unit -> t
val of_bytes : bytes -> t
val contents : t -> string
val clear_and_zero : t -> unit

Clear the buffer and zero out its storage.

  • since 0.15
val bytes_slice : t -> bytes

Access underlying slice of bytes.

  • since 0.5
val contents_and_clear : t -> string

Get contents of the buffer and clear it.

  • since 0.5
val add_char : t -> char -> unit

Add a single char.

  • 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 0.14
val add_buffer : t -> Stdlib.Buffer.t -> unit

Append bytes from buffer.

  • since 0.14
diff --git a/tiny_httpd/Tiny_httpd_core/Headers/index.html b/tiny_httpd/Tiny_httpd_core/Headers/index.html new file mode 100644 index 00000000..d4e0a986 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Headers/index.html @@ -0,0 +1,2 @@ + +Headers (tiny_httpd.Tiny_httpd_core.Headers)

Module Tiny_httpd_core.Headers

Headers

Headers are metadata associated with a request or response.

type t = (string * string) list

The header files of a request or response.

Neither the key nor the value can contain '\r' or '\n'. See https://tools.ietf.org/html/rfc7230#section-3.2

val empty : t

Empty list of headers.

  • since 0.5
val get : ?f:(string -> string) -> string -> t -> string option

get k headers looks for the header field with key k.

  • parameter f

    if provided, will transform the value before it is returned.

val get_exn : ?f:(string -> string) -> string -> t -> string
  • raises Not_found
val set : string -> string -> t -> t

set k v headers sets the key k to value v. It erases any previous entry for k

val remove : string -> t -> t

Remove the key from the headers, if present.

val contains : string -> t -> bool

Is there a header with the given key?

val pp : Stdlib.Format.formatter -> t -> unit

Pretty print the headers.

val parse_ : buf:Buf.t -> IO.Input.t -> t
diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-bufferized/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-bufferized/index.html new file mode 100644 index 00000000..b4a42ffa --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-bufferized/index.html @@ -0,0 +1,2 @@ + +bufferized (tiny_httpd.Tiny_httpd_core.IO.Input.bufferized)

Class Input.bufferized

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_bytes/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_bytes/index.html new file mode 100644 index 00000000..78613320 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_bytes/index.html @@ -0,0 +1,2 @@ + +of_bytes (tiny_httpd.Tiny_httpd_core.IO.Input.of_bytes)

Class Input.of_bytes

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_in_channel/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_in_channel/index.html new file mode 100644 index 00000000..2038bcab --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_in_channel/index.html @@ -0,0 +1,2 @@ + +of_in_channel (tiny_httpd.Tiny_httpd_core.IO.Input.of_in_channel)

Class Input.of_in_channel

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_string/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_string/index.html new file mode 100644 index 00000000..d572439b --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-of_string/index.html @@ -0,0 +1,2 @@ + +of_string (tiny_httpd.Tiny_httpd_core.IO.Input.of_string)

Class Input.of_string

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-open_file/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-open_file/index.html new file mode 100644 index 00000000..11b04d8e --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-open_file/index.html @@ -0,0 +1,2 @@ + +open_file (tiny_httpd.Tiny_httpd_core.IO.Input.open_file)

Class Input.open_file

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-t_from_refill/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-t_from_refill/index.html new file mode 100644 index 00000000..16c166a6 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-t_from_refill/index.html @@ -0,0 +1,2 @@ + +t_from_refill (tiny_httpd.Tiny_httpd_core.IO.Input.t_from_refill)

Class Input.t_from_refill

A mixin to implement a buffered input by only providing a refill method. Add a close method and it's good to go.

method private virtual refill : Iostream__.Slice.t -> unit

Implementation of the stream: this takes a slice, resets its offset, and fills it with bytes. It must write at least one byte in the slice, unless the underlying input has reached its end.

method input : bytes -> int -> int -> int
method fill_buf : unit -> Iostream__.Slice.t
method consume : int -> unit
diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/class-type-t/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/class-type-t/index.html new file mode 100644 index 00000000..a015b7dd --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (tiny_httpd.Tiny_httpd_core.IO.Input.t)

Class type Input.t

The implementation of buffered input streams.

inherit Iostream__.In.t
method fill_buf : unit -> Iostream__.Slice.t

ic#fill_buf() returns a slice into the ic's internal buffer, and ensures it's empty only if ic.ic is empty. In other words, the invariant is that this only returns an empty slice if the input stream is exhausted.

method consume : int -> unit

Consume n bytes from the inner buffer. This is only valid if the last call to fill_buf returned a slice with at least n bytes.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Input/index.html b/tiny_httpd/Tiny_httpd_core/IO/Input/index.html new file mode 100644 index 00000000..0869bafc --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Input/index.html @@ -0,0 +1,29 @@ + +Input (tiny_httpd.Tiny_httpd_core.IO.Input)

Module IO.Input

Input channel (byte source)

include module type of struct include Iostream.In_buf end
class type t = object ... end

The implementation of buffered input streams.

class virtual t_from_refill : ?bytes:bytes -> unit -> object ... end

A mixin to implement a buffered input by only providing a refill method. Add a close method and it's good to go.

val create : + ?bytes:bytes -> + ?close:(unit -> unit) -> + refill:(bytes -> int) -> + unit -> + t

Create a new buffered input stream.

  • parameter refill

    will be called to refill the content of the bytes, returning how many bytes were added (starting at offset 0).

  • parameter buf

    the underlying buffer

  • raises Invalid_argument

    if the buffer's length is not at least 16.

class of_bytes : ?off:int -> ?len:int -> bytes -> t
val of_bytes : ?off:int -> ?len:int -> bytes -> t
class of_string : ?off:int -> ?len:int -> string -> t
val of_string : ?off:int -> ?len:int -> string -> t
class bufferized : ?bytes:bytes -> Iostream.In.t -> t
val bufferized : ?bytes:bytes -> Iostream.In.t -> t

Read from the given buffer.

  • parameter off

    initial offset (default 0)

  • parameter len

    length of the slice in the bytes. (default all available bytes from offset)

class of_in_channel : ?bytes:bytes -> in_channel -> t
val of_in_channel : ?bytes:bytes -> in_channel -> t

Wrap a standard input channel.

class open_file : ?bytes:bytes -> ?mode:int -> ?flags:open_flag list -> string -> t
val open_file : + ?bytes:bytes -> + ?mode:int -> + ?flags:open_flag list -> + string -> + t
val with_open_file : + ?bytes:bytes -> + ?mode:int -> + ?flags:open_flag list -> + string -> + (t -> 'a) -> + 'a
val fill_buf : t -> Iostream.Slice.t

fill_buffer bic returns a slice into bic's internal buffer, and ensures it's empty only if bic.ic is empty.

val of_in : ?bytes:bytes -> Iostream.In.t -> t

Make a buffered version of the input stream.

  • parameter bytes

    the buffer to use.

  • raises Invalid_argument

    if the buffer's length is not at least 16.

val consume : t -> int -> unit

consume bic n consumes n bytes from bic. Precondition: n <= get_len bic, ie. one cannot consume bytes that have not yet been obtained via fill_buffer or fill_and_get.

val into_in : t -> Iostream.In.t

Cast into a In.t. This doesn't allocate.

val input_all_into_buffer : t -> Stdlib.Buffer.t -> unit

Read the whole content into the given buffer.

val input_all : ?buf:bytes -> t -> string

input_all ic reads the whole content of ic into a string.

  • parameter buf

    the initial buffer to use internally.

  • since 0.2
val copy_into : t -> Iostream.Out.t -> unit

Copy the entire stream into the given output.

val skip : t -> int -> unit

skip ic n reads and dicards the next n bytes in ic.

val input_line : ?buffer:Stdlib.Buffer.t -> t -> string option

Read a line from the input. Return None if the stream is empty.

  • parameter buffer

    a buffer to use to hold the line.

val input_lines : ?buffer:Stdlib.Buffer.t -> t -> string list

Read all lines from the input.

val to_iter : t -> (char -> unit) -> unit
val to_seq : t -> char Stdlib.Seq.t
val of_seq : ?bytes:bytes -> char Stdlib.Seq.t -> t
val of_unix_fd : + ?close_noerr:bool -> + closed:bool ref -> + buf:Slice.t -> + Unix.file_descr -> + t
val of_slice : Slice.t -> t
val input : t -> bytes -> int -> int -> int

Read into the given slice.

  • returns

    the number of bytes read, 0 means end of input.

val close : < close : unit -> unit.. > -> unit

Close the channel.

val really_input : t -> bytes -> int -> int -> unit

Read exactly len bytes.

  • raises End_of_file

    if the input did not contain enough data.

val append : t -> t -> t
val iter_slice : (Slice.t -> unit) -> t -> unit
val iter : (bytes -> int -> int -> unit) -> t -> unit
val to_chan : out_channel -> t -> unit
val to_chan' : Iostream.Out.t -> t -> unit
val read_all_using : buf:Buf.t -> t -> string
val read_exactly_ : too_short:(unit -> unit) -> t -> bytes -> int -> unit

Read n bytes from the input into bytes.

val read_line_into : t -> buf:Buf.t -> unit

read a line into the buffer, after clearing it.

val read_line_using : buf:Buf.t -> t -> string
val read_line_using_opt : buf:Buf.t -> t -> string option
val reading_exactly_ : + skip_on_close:bool -> + close_rec:bool -> + size:int -> + bytes:bytes -> + t -> + t
val limit_size_to : close_rec:bool -> max_size:int -> bytes:bytes -> t -> t

new stream with maximum size max_size.

  • parameter close_rec

    if true, closing this will also close the input stream

val reading_exactly : close_rec:bool -> size:int -> bytes:bytes -> t -> t

New stream that consumes exactly size bytes from the input. If fewer bytes are read before close is called, we read and discard the remaining quota of bytes before close returns.

  • parameter close_rec

    if true, closing this will also close the input stream

val read_chunked : bytes:bytes -> fail:(string -> exn) -> t -> t
val output_chunked' : ?buf:Buf.t -> Iostream.Out_buf.t -> t -> unit

Output a stream using chunked encoding

val output_chunked : ?buf:Buf.t -> out_channel -> t -> unit

print a stream as a series of chunks

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-bufferized/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-bufferized/index.html new file mode 100644 index 00000000..6e6eb450 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-bufferized/index.html @@ -0,0 +1,2 @@ + +bufferized (tiny_httpd.Tiny_httpd_core.IO.Output.bufferized)

Class Output.bufferized

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-dummy/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-dummy/index.html new file mode 100644 index 00000000..23140f44 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-dummy/index.html @@ -0,0 +1,2 @@ + +dummy (tiny_httpd.Tiny_httpd_core.IO.Output.dummy)

Class Output.dummy

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_buffer/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_buffer/index.html new file mode 100644 index 00000000..4bde3d9f --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_buffer/index.html @@ -0,0 +1,2 @@ + +of_buffer (tiny_httpd.Tiny_httpd_core.IO.Output.of_buffer)

Class Output.of_buffer

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_out_channel/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_out_channel/index.html new file mode 100644 index 00000000..c2ab9fd6 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_out_channel/index.html @@ -0,0 +1,2 @@ + +of_out_channel (tiny_httpd.Tiny_httpd_core.IO.Output.of_out_channel)

Class Output.of_out_channel

inherit t
inherit Iostream__.Seekable.t
diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_unix_fd/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_unix_fd/index.html new file mode 100644 index 00000000..05c26392 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-of_unix_fd/index.html @@ -0,0 +1,2 @@ + +of_unix_fd (tiny_httpd.Tiny_httpd_core.IO.Output.of_unix_fd)

Class Output.of_unix_fd

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-open_file/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-open_file/index.html new file mode 100644 index 00000000..76fd6e93 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-open_file/index.html @@ -0,0 +1,2 @@ + +open_file (tiny_httpd.Tiny_httpd_core.IO.Output.open_file)

Class Output.open_file

inherit t
inherit Iostream__.Seekable.t
diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-t_from_output/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-t_from_output/index.html new file mode 100644 index 00000000..aabdddef --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-t_from_output/index.html @@ -0,0 +1,2 @@ + +t_from_output (tiny_httpd.Tiny_httpd_core.IO.Output.t_from_output)

Class Output.t_from_output

Make a bufferized output from a non bufferized output+close.

inherit t
method private virtual output_underlying : bytes -> int -> int -> unit

Emit these private bytes, unbufferized

method private virtual close_underlying : unit -> unit

Close the underlying output. The bufferized output will flush and then call this.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-type-t/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-type-t/index.html new file mode 100644 index 00000000..947c49f4 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-type-t/index.html @@ -0,0 +1,2 @@ + +t (tiny_httpd.Tiny_httpd_core.IO.Output.t)

Class type Output.t

An output stream, ie. a place into which we can write bytes, with a buffer to amortize the cost of operations.

This can be a Buffer.t, an out_channel, a Unix.file_descr, etc.

inherit Iostream__.Out.t
method output_char : char -> unit

Output a single char

method flush : unit -> unit

Flush underlying buffer

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/class-type-t_seekable/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/class-type-t_seekable/index.html new file mode 100644 index 00000000..4cab02cf --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/class-type-t_seekable/index.html @@ -0,0 +1,2 @@ + +t_seekable (tiny_httpd.Tiny_httpd_core.IO.Output.t_seekable)

Class type Output.t_seekable

inherit t
inherit Iostream__.Seekable.t
diff --git a/tiny_httpd/Tiny_httpd_core/IO/Output/index.html b/tiny_httpd/Tiny_httpd_core/IO/Output/index.html new file mode 100644 index 00000000..1021c92c --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Output/index.html @@ -0,0 +1,21 @@ + +Output (tiny_httpd.Tiny_httpd_core.IO.Output)

Module IO.Output

Output channel (byte sink)

include module type of struct include Iostream.Out_buf end
class type t = object ... end

An output stream, ie. a place into which we can write bytes, with a buffer to amortize the cost of operations.

class type t_seekable = object ... end
val create : + ?flush:(unit -> unit) -> + ?close:(unit -> unit) -> + output_char:(char -> unit) -> + output:(bytes -> int -> int -> unit) -> + unit -> + t

Create a new output stream from raw components.

class dummy : t
val dummy : t

Dummy output, drops everything written to it.

class virtual t_from_output : ?bytes:bytes -> unit -> object ... end

Make a bufferized output from a non bufferized output+close.

class bufferized : ?bytes:bytes -> Iostream.Out.t -> t
val bufferized : ?bytes:bytes -> Iostream.Out.t -> t
class of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable
val of_out_channel : ?close_noerr:bool -> out_channel -> t_seekable

Wrap an out channel.

val of_buffer : Stdlib.Buffer.t -> t

of_buffer buf is an output channel that writes directly into buf. flush and close have no effect.

class open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string -> + t_seekable
val open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + t_seekable

open_file file creates an out stream writing into the given file.

  • parameter mode

    permissions for the file creation

  • parameter flags

    set of unix flags to use. It must contain write permissions.

val with_open_file : + ?close_noerr:bool -> + ?mode:int -> + ?flags:open_flag list -> + string -> + (t_seekable -> 'a) -> + 'a
val output_char : t -> char -> unit

Output a single char

val output : t -> bytes -> int -> int -> unit

Write the slice of bytes.

val close : t -> unit

Close the stream. Idempotent.

val flush : t -> unit

Ensure the bytes written so far are indeed written to the underlying storage/network socket/… and are not just sitting in a buffer.

val output_string : t -> string -> unit

Output the whole string.

val output_line : t -> string -> unit

Output the whole string followed by '\n'.

  • since 0.2
val output_lines : t -> string Stdlib.Seq.t -> unit

Output a series of lines, each terminated by '\n'.

val output_int : t -> int -> unit

Output an integer in decimal notation.

val tee : t list -> t

tee ocs is an output that accepts bytes and writes them to every output in ocs. When closed, it closes all elements of oc.

val map_char : (char -> char) -> t -> t

Transform the stream byte by byte

class of_unix_fd : ?close_noerr:bool option -> closed:bool ref -> buf:Slice.t -> Unix.file_descr -> + t
val output_buf : t -> Buf.t -> unit
val chunk_encoding : ?buf:Buf.t -> close_rec:bool -> t -> t

chunk_encoding oc makes a new channel that outputs its content into oc in chunk encoding form.

  • parameter close_rec

    if true, closing the result will also close oc

  • parameter buf

    a buffer used to accumulate data into chunks. Chunks are emitted when buf's size gets over a certain threshold, or when flush is called.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/TCP_server/index.html b/tiny_httpd/Tiny_httpd_core/IO/TCP_server/index.html new file mode 100644 index 00000000..2b14fbf4 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/TCP_server/index.html @@ -0,0 +1,2 @@ + +TCP_server (tiny_httpd.Tiny_httpd_core.IO.TCP_server)

Module IO.TCP_server

A TCP server abstraction.

type conn_handler = {
  1. handle : client_addr:Unix.sockaddr -> Input.t -> Output.t -> unit;
    (*

    Handle client connection

    *)
}
type t = {
  1. endpoint : unit -> string * int;
    (*

    Endpoint we listen on. This can only be called from within serve.

    *)
  2. active_connections : unit -> int;
    (*

    Number of connections currently active

    *)
  3. running : unit -> bool;
    (*

    Is the server currently running?

    *)
  4. stop : unit -> unit;
    (*

    Ask the server to stop. This might not take effect immediately, and is idempotent. After this server.running() must return false.

    *)
}

A running TCP server.

This contains some functions that provide information about the running server, including whether it's active (as opposed to stopped), a function to stop it, and statistics about the number of connections.

type builder = {
  1. serve : after_init:(t -> unit) -> handle:conn_handler -> unit -> unit;
    (*

    Blocking call to listen for incoming connections and handle them. Uses the connection handler handle to handle individual client connections in individual threads/fibers/tasks.

    • parameter after_init

      is called once with the server after the server has started.

    *)
}

A TCP server builder implementation.

Calling builder.serve ~after_init ~handle () starts a new TCP server on an unspecified endpoint (most likely coming from the function returning this builder) and returns the running server.

diff --git a/tiny_httpd/Tiny_httpd_core/IO/Writer/index.html b/tiny_httpd/Tiny_httpd_core/IO/Writer/index.html new file mode 100644 index 00000000..2f1ba380 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/Writer/index.html @@ -0,0 +1,2 @@ + +Writer (tiny_httpd.Tiny_httpd_core.IO.Writer)

Module IO.Writer

A writer abstraction.

type t = {
  1. write : Output.t -> unit;
}

Writer.

A writer is a push-based stream of bytes. Give it an output channel and it will write the bytes in it.

This is useful for responses: an http endpoint can return a writer as its response's body; the writer is given access to the connection to the client and can write into it as if it were a regular out_channel, including controlling calls to flush. Tiny_httpd will convert these writes into valid HTTP chunks.

  • since 0.14
val make : write:(Output.t -> unit) -> unit -> t
val write : Output.t -> t -> unit

Write into the channel.

val empty : t

Empty writer, will output 0 bytes.

val of_string : string -> t

A writer that just emits the bytes from the given string.

val of_input : Input.t -> t
diff --git a/tiny_httpd/Tiny_httpd_core/IO/index.html b/tiny_httpd/Tiny_httpd_core/IO/index.html new file mode 100644 index 00000000..683fb82d --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/IO/index.html @@ -0,0 +1,2 @@ + +IO (tiny_httpd.Tiny_httpd_core.IO)

Module Tiny_httpd_core.IO

IO abstraction.

We abstract IO so we can support classic unix blocking IOs with threads, and modern async IO with Eio.

NOTE: experimental.

module Buf = Buf
module Slice = Iostream.Slice
module Output : sig ... end

Output channel (byte sink)

module Input : sig ... end

Input channel (byte source)

module Writer : sig ... end

A writer abstraction.

module TCP_server : sig ... end

A TCP server abstraction.

diff --git a/tiny_httpd/Tiny_httpd_core/Log/index.html b/tiny_httpd/Tiny_httpd_core/Log/index.html new file mode 100644 index 00000000..f805e4c5 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Log/index.html @@ -0,0 +1,8 @@ + +Log (tiny_httpd.Tiny_httpd_core.Log)

Module Tiny_httpd_core.Log

Logging for tiny_httpd

val info : + ((('a, Stdlib.Format.formatter, unit, unit) format4 -> 'a) -> unit) -> + unit
val debug : + ((('a, Stdlib.Format.formatter, unit, unit) format4 -> 'a) -> unit) -> + unit
val error : + ((('a, Stdlib.Format.formatter, unit, unit) format4 -> 'a) -> unit) -> + unit
val setup : debug:bool -> unit -> unit

Setup and enable logging. This should only ever be used in executables, not libraries.

  • parameter debug

    if true, set logging to debug (otherwise info)

val dummy : bool
diff --git a/tiny_httpd/Tiny_httpd_core/Meth/index.html b/tiny_httpd/Tiny_httpd_core/Meth/index.html new file mode 100644 index 00000000..20cc03b2 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Meth/index.html @@ -0,0 +1,2 @@ + +Meth (tiny_httpd.Tiny_httpd_core.Meth)

Module Tiny_httpd_core.Meth

HTTP Methods

type t = [
  1. | `GET
  2. | `PUT
  3. | `POST
  4. | `HEAD
  5. | `DELETE
  6. | `OPTIONS
]

A HTTP method. For now we only handle a subset of these.

See https://tools.ietf.org/html/rfc7231#section-4

val pp : Stdlib.Format.formatter -> t -> unit
val to_string : t -> string
val of_string : string -> t
diff --git a/tiny_httpd/Tiny_httpd_pool/index.html b/tiny_httpd/Tiny_httpd_core/Pool/index.html similarity index 61% rename from tiny_httpd/Tiny_httpd_pool/index.html rename to tiny_httpd/Tiny_httpd_core/Pool/index.html index b43e9812..6fcbd66b 100644 --- a/tiny_httpd/Tiny_httpd_pool/index.html +++ b/tiny_httpd/Tiny_httpd_core/Pool/index.html @@ -1,5 +1,5 @@ -Tiny_httpd_pool (tiny_httpd.Tiny_httpd_pool)

Module Tiny_httpd_pool

Resource pool.

This pool is used for buffers. It can be used for other resources but do note that it assumes resources are still reasonably cheap to produce and discard, and will never block waiting for a resource — it's not a good pool for DB connections.

type 'a t

Pool of values of type 'a

val create : +Pool (tiny_httpd.Tiny_httpd_core.Pool)

Module Tiny_httpd_core.Pool

Resource pool.

This pool is used for buffers. It can be used for other resources but do note that it assumes resources are still reasonably cheap to produce and discard, and will never block waiting for a resource — it's not a good pool for DB connections.

  • since 0.14.
type 'a t

Pool of values of type 'a

val create : ?clear:('a -> unit) -> mk_item:(unit -> 'a) -> ?max_size:int -> diff --git a/tiny_httpd/Tiny_httpd_core/Request/index.html b/tiny_httpd/Tiny_httpd_core/Request/index.html new file mode 100644 index 00000000..d0a71d86 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Request/index.html @@ -0,0 +1,14 @@ + +Request (tiny_httpd.Tiny_httpd_core.Request)

Module Tiny_httpd_core.Request

Requests

Requests are sent by a client, e.g. a web browser or cURL. From the point of view of the server, they're inputs.

type 'body t = private {
  1. meth : Meth.t;
    (*

    HTTP method for this request.

    *)
  2. host : string;
    (*

    Host header, mandatory. It can also be found in headers.

    *)
  3. client_addr : Unix.sockaddr;
    (*

    Client address. Available since 0.14.

    *)
  4. headers : Headers.t;
    (*

    List of headers.

    *)
  5. mutable meta : Hmap.t;
    (*

    Metadata.

    • since NEXT_RELEASE
    *)
  6. http_version : int * int;
    (*

    HTTP version. This should be either 1, 0 or 1, 1.

    *)
  7. path : string;
    (*

    Full path of the requested URL.

    *)
  8. path_components : string list;
    (*

    Components of the path of the requested URL.

    *)
  9. query : (string * string) list;
    (*

    Query part of the requested URL.

    *)
  10. body : 'body;
    (*

    Body of the request.

    *)
  11. start_time : float;
    (*

    Obtained via get_time_s in create

    • since 0.11
    *)
}

A request with method, path, host, headers, and a body, sent by a client.

The body is polymorphic because the request goes through several transformations. First it has no body, as only the request and headers are read; then it has a stream body; then the body might be entirely read as a string via read_body_full.

  • since 0.6 The field [query] was added and contains the query parameters in ["?foo=bar,x=y"]
  • since 0.6 The field [path_components] is the part of the path that precedes [query] and is split on ["/"].
  • since 0.11 the type is a private alias
  • since 0.11 the field [start_time] was added
val add_meta : _ t -> 'a Hmap.key -> 'a -> unit

Add metadata

  • since NEXT_RELEASE
val get_meta : _ t -> 'a Hmap.key -> 'a option

Get metadata

  • since NEXT_RELEASE
val get_meta_exn : _ t -> 'a Hmap.key -> 'a

Like get_meta but can fail

  • raises Invalid_argument

    if not present

  • since NEXT_RELEASE
val pp_with : + ?mask_header:(string -> bool) -> + ?headers_to_mask:string list -> + ?show_query:bool -> + ?pp_body:(Stdlib.Format.formatter -> 'body -> unit) -> + unit -> + Stdlib.Format.formatter -> + 'body t -> + unit

Pretty print the request. The exact format of this printing is not specified.

  • parameter mask_header

    function which is given each header name. If it returns true, the header's value is masked. The presence of the header is still printed. Default fun _ -> false.

  • parameter headers_to_mask

    a list of headers masked by default. Default is "authorization"; "cookie". @show_query if true (default true), the query part of the request is shown.

  • parameter pp_body

    body printer (default prints "?" instead of the body, which works even for stream bodies)

val pp : Stdlib.Format.formatter -> string t -> unit

Pretty print the request and its body. The exact format of this printing is not specified.

val pp_ : Stdlib.Format.formatter -> _ t -> unit

Pretty print the request without its body. The exact format of this printing is not specified.

val headers : _ t -> Headers.t

List of headers of the request, including "Host".

val get_header : ?f:(string -> string) -> _ t -> string -> string option

get_header req h looks up header h in req. It returns None if the header is not present. This is case insensitive and should be used rather than looking up h verbatim in headers.

val get_header_int : _ t -> string -> int option

Same as get_header but also performs a string to integer conversion.

val set_header : string -> string -> 'a t -> 'a t

set_header k v req sets k: v in the request req's headers.

val remove_header : string -> 'a t -> 'a t

Remove one instance of this header.

  • since NEXT_RELEASE
val update_headers : (Headers.t -> Headers.t) -> 'a t -> 'a t

Modify headers using the given function.

  • since 0.11
val set_body : 'a -> _ t -> 'a t

set_body b req returns a new query whose body is b.

  • since 0.11
val host : _ t -> string

Host field of the request. It also appears in the headers.

val client_addr : _ t -> Unix.sockaddr

Client address of the request.

  • since 0.16
val meth : _ t -> Meth.t

Method for the request.

val path : _ t -> string

Request path.

val query : _ t -> (string * string) list

Decode the query part of the path field.

  • since 0.4
val body : 'b t -> 'b

Request body, possibly empty.

val start_time : _ t -> float

time stamp (from Unix.gettimeofday) after parsing the first line of the request

  • since 0.11
val limit_body_size : + max_size:int -> + bytes:bytes -> + IO.Input.t t -> + IO.Input.t t

Limit the body size to max_size bytes, or return a 413 error.

  • since 0.3
val read_body_full : ?bytes:bytes -> ?buf_size:int -> IO.Input.t t -> string t

Read the whole body into a string. Potentially blocking.

  • parameter buf_size

    initial size of underlying buffer (since 0.11)

  • parameter bytes

    the initial buffer (since 0.14)

diff --git a/tiny_httpd/Tiny_httpd_core/Response/index.html b/tiny_httpd/Tiny_httpd_core/Response/index.html new file mode 100644 index 00000000..37323315 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Response/index.html @@ -0,0 +1,26 @@ + +Response (tiny_httpd.Tiny_httpd_core.Response)

Module Tiny_httpd_core.Response

Responses

Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t

type body = [
  1. | `String of string
  2. | `Stream of IO.Input.t
  3. | `Writer of IO.Writer.t
  4. | `Void
]

Body of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events notably).

  • `String str replies with a body set to this string, and a known content-length.
  • `Stream str replies with a body made from this string, using chunked encoding.
  • `Void replies with no body.
  • `Writer w replies with a body created by the writer w, using a chunked encoding. It is available since 0.14.
type t = private {
  1. code : Response_code.t;
    (*

    HTTP response code. See Response_code.

    *)
  2. headers : Headers.t;
    (*

    Headers of the reply. Some will be set by Tiny_httpd automatically.

    *)
  3. body : body;
    (*

    Body of the response. Can be empty.

    *)
}

A response to send back to a client.

val set_body : body -> t -> t

Set the body of the response.

  • since 0.11
val set_header : string -> string -> t -> t

Set a header.

  • since 0.11
val update_headers : (Headers.t -> Headers.t) -> t -> t

Modify headers.

  • since 0.11
val remove_header : string -> t -> t

Remove one instance of this header.

  • since NEXT_RELEASE
val set_headers : Headers.t -> t -> t

Set all headers.

  • since 0.11
val set_code : Response_code.t -> t -> t

Set the response code.

  • since 0.11
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> t

Make a response from its raw components, with a string body. Use "" to not send a body at all.

val make_raw_stream : + ?headers:Headers.t -> + code:Response_code.t -> + IO.Input.t -> + t

Same as make_raw but with a stream body. The body will be sent with the chunked transfer-encoding.

val make_void : ?headers:Headers.t -> code:int -> unit -> t

Return a response without a body at all.

  • since 0.13
val make : + ?headers:Headers.t -> + ?code:int -> + (body, Response_code.t * string) result -> + t

make r turns a result into a response.

  • make (Ok body) replies with 200 and the body.
  • make (Error (code,msg)) replies with the given error code and message as body.
val make_string : + ?headers:Headers.t -> + ?code:int -> + (string, Response_code.t * string) result -> + t

Same as make but with a string body.

val make_writer : + ?headers:Headers.t -> + ?code:int -> + (IO.Writer.t, Response_code.t * string) result -> + t

Same as make but with a writer body.

val make_stream : + ?headers:Headers.t -> + ?code:int -> + (IO.Input.t, Response_code.t * string) result -> + t

Same as make but with a stream body.

val fail : + ?headers:Headers.t -> + code:int -> + ('a, unit, string, t) format4 -> + 'a

Make the current request fail with the given code and message. Example: fail ~code:404 "oh noes, %s not found" "waldo".

exception Bad_req of int * string

Exception raised by fail_raise with the HTTP code and body

val fail_raise : code:int -> ('a, unit, string, 'b) format4 -> 'a

Similar to fail but raises an exception that exits the current handler. This should not be used outside of a (path) handler. Example: fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()

val pp : Stdlib.Format.formatter -> t -> unit

Pretty print the response. The exact format is not specified.

diff --git a/tiny_httpd/Tiny_httpd_core/Response_code/index.html b/tiny_httpd/Tiny_httpd_core/Response_code/index.html new file mode 100644 index 00000000..f4c102df --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Response_code/index.html @@ -0,0 +1,2 @@ + +Response_code (tiny_httpd.Tiny_httpd_core.Response_code)

Module Tiny_httpd_core.Response_code

Response Codes

type t = int

A standard HTTP code.

https://tools.ietf.org/html/rfc7231#section-6

val ok : t

The code 200

val not_found : t

The code 404

val descr : t -> string

A description of some of the error codes. NOTE: this is not complete (yet).

val is_success : t -> bool

is_success code is true iff code is in the 2xx or 3xx range.

  • since NEXT_RELEASE
diff --git a/tiny_httpd/Tiny_httpd_core/Route/Private_/index.html b/tiny_httpd/Tiny_httpd_core/Route/Private_/index.html new file mode 100644 index 00000000..4b7aa68e --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Route/Private_/index.html @@ -0,0 +1,2 @@ + +Private_ (tiny_httpd.Tiny_httpd_core.Route.Private_)

Module Route.Private_

val eval : string list -> ('a, 'b) t -> 'a -> 'b option
diff --git a/tiny_httpd/Tiny_httpd_core/Route/index.html b/tiny_httpd/Tiny_httpd_core/Route/index.html new file mode 100644 index 00000000..8489a803 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Route/index.html @@ -0,0 +1,2 @@ + +Route (tiny_httpd.Tiny_httpd_core.Route)

Module Tiny_httpd_core.Route

Routing

Basic type-safe routing of handlers based on URL paths. This is optional, it is possible to only define the root handler with something like Routes.

  • since 0.6
type ('a, 'b) comp

An atomic component of a path

type ('a, 'b) t

A route, composed of path components

val int : (int -> 'a, 'a) comp

Matches an integer.

val string : (string -> 'a, 'a) comp

Matches a string not containing '/' and binds it as is.

val string_urlencoded : (string -> 'a, 'a) comp

Matches a URL-encoded string, and decodes it.

val exact : string -> ('a, 'a) comp

exact "s" matches "s" and nothing else.

val return : ('a, 'a) t

Matches the empty path.

val rest_of_path : (string -> 'a, 'a) t

Matches a string, even containing '/'. This will match the entirety of the remaining route.

  • since 0.7
val rest_of_path_urlencoded : (string -> 'a, 'a) t

Matches a string, even containing '/', an URL-decode it. This will match the entirety of the remaining route.

  • since 0.7
val (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t

comp / route matches "foo/bar/…" iff comp matches "foo", and route matches "bar/…".

val exact_path : string -> ('a, 'b) t -> ('a, 'b) t

exact_path "foo/bar/..." r is equivalent to exact "foo" @/ exact "bar" @/ ... @/ r

  • since 0.11 *
val pp : Stdlib.Format.formatter -> (_, _) t -> unit

Print the route.

  • since 0.7
val to_string : (_, _) t -> string

Print the route.

  • since 0.7
module Private_ : sig ... end
diff --git a/tiny_httpd/Tiny_httpd_core/Server/Middleware/index.html b/tiny_httpd/Tiny_httpd_core/Server/Middleware/index.html new file mode 100644 index 00000000..8ef1c44c --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Server/Middleware/index.html @@ -0,0 +1,2 @@ + +Middleware (tiny_httpd.Tiny_httpd_core.Server.Middleware)

Module Server.Middleware

type handler = IO.Input.t Request.t -> resp:(Response.t -> unit) -> unit

Handlers are functions returning a response to a request. The response can be delayed, hence the use of a continuation as the resp parameter.

type t = handler -> handler

A middleware is a handler transformation.

It takes the existing handler h, and returns a new one which, given a query, modify it or log it before passing it to h, or fail. It can also log or modify or drop the response.

val nil : t

Trivial middleware that does nothing.

diff --git a/tiny_httpd/Tiny_httpd_core/Server/index.html b/tiny_httpd/Tiny_httpd_core/Server/index.html new file mode 100644 index 00000000..75deb950 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Server/index.html @@ -0,0 +1,41 @@ + +Server (tiny_httpd.Tiny_httpd_core.Server)

Module Tiny_httpd_core.Server

HTTP server.

This module implements a very simple, basic HTTP/1.1 server using blocking IOs and threads.

It is possible to use a thread pool, see create's argument new_thread.

  • since 0.13

Middlewares

A middleware can be inserted in a handler to modify or observe its behavior.

  • since 0.11
module Middleware : sig ... end

Main Server type

type t

A HTTP server. See create for more details.

module type IO_BACKEND = sig ... end

A backend that provides IO operations, network operations, etc.

val create_from : + ?buf_size:int -> + ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> + backend:(module IO_BACKEND) -> + unit -> + t

Create a new webserver using provided backend.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter buf_size

    size for buffers (since 0.11)

  • since 0.14
val addr : t -> string

Address on which the server listens.

val is_ipv6 : t -> bool

is_ipv6 server returns true iff the address of the server is an IPv6 address.

  • since 0.3
val port : t -> int

Port on which the server listens. Note that this might be different than the port initially given if the port was 0 (meaning that the OS picks a port for us).

val active_connections : t -> int

Number of currently active connections.

val add_decode_request_cb : + t -> + (unit Request.t -> (unit Request.t * (IO.Input.t -> IO.Input.t)) option) -> + unit

Add a callback for every request. The callback can provide a stream transformer and a new request (with modified headers, typically). A possible use is to handle decompression by looking for a Transfer-Encoding header and returning a stream transformer that decompresses on the fly.

val add_encode_response_cb : + t -> + (unit Request.t -> Response.t -> Response.t option) -> + unit

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. The callback is given the query with only its headers, as well as the current response.

val add_middleware : + stage:[ `Encoding | `Stage of int ] -> + t -> + Middleware.t -> + unit

Add a middleware to every request/response pair.

  • parameter stage

    specify when middleware applies. Encoding comes first (outermost layer), then stages in increasing order.

  • raises Invalid_argument

    if stage is `Stage n where n < 1

  • since 0.11

Request handlers

val set_top_handler : t -> (IO.Input.t Request.t -> Response.t) -> unit

Setup a handler called by default.

This handler is called with any request not accepted by any handler installed via add_path_handler. 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 0.14 . Use Request.read_body_full to read the body into a string if needed.

val add_route_handler : + ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> + ?middlewares:Middleware.t list -> + ?meth:Meth.t -> + t -> + ('a, string Request.t -> Response.t) Route.t -> + 'a -> + unit

add_route_handler server Route.(exact "path" @/ string @/ int @/ return) f calls f "foo" 42 request when a request with path "path/foo/42/" is received.

Note that the handlers are called in the reverse order of their addition, so the last registered handler can override previously registered ones.

  • parameter meth

    if provided, only accept requests with the given method. Typically one could react to `GET or `PUT.

  • parameter accept

    should return Ok() if the given request (before its body is read) should be accepted, Error (code,message) if it's to be rejected (e.g. because its content is too big, or for some permission error). See the http_of_dir program for an example of how to use accept to filter uploads that are too large before the upload even starts. The default always returns Ok(), i.e. it accepts all requests.

  • since 0.6
val add_route_handler_stream : + ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> + ?middlewares:Middleware.t list -> + ?meth:Meth.t -> + t -> + ('a, IO.Input.t Request.t -> Response.t) Route.t -> + 'a -> + unit

Similar to add_route_handler, but where the body of the request is a stream of bytes that has not been read yet. This is useful when one wants to stream the body directly into a parser, json decoder (such as Jsonm) or into a file.

  • since 0.6

Server-sent events

EXPERIMENTAL: this API is not stable yet.

module type SERVER_SENT_GENERATOR = sig ... end

A server-side function to generate of Server-sent events.

type server_sent_generator = (module SERVER_SENT_GENERATOR)

Server-sent event generator. This generates events that are forwarded to the client (e.g. the browser).

  • since 0.9
val add_route_server_sent_handler : + ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> + t -> + ('a, string Request.t -> server_sent_generator -> unit) Route.t -> + 'a -> + unit

Add a handler on an endpoint, that serves server-sent events.

The callback is given a generator that can be used to send events as it pleases. The connection is always closed by the client, and the accepted method is always GET. This will set the header "content-type" to "text/event-stream" automatically and reply with a 200 immediately. See server_sent_generator for more details.

This handler stays on the original thread (it is synchronous).

  • since 0.9

Upgrade handlers

These handlers upgrade the connection to another protocol.

  • since NEXT_RELEASE
module type UPGRADE_HANDLER = sig ... end

Handler that upgrades to another protocol.

type upgrade_handler = (module UPGRADE_HANDLER)
  • since NEXT_RELEASE
val add_upgrade_handler : + ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> + t -> + ('a, upgrade_handler) Route.t -> + 'a -> + unit

Run the server

val running : t -> bool

Is the server running?

  • since 0.14
val stop : t -> unit

Ask the server to stop. This might not have an immediate effect as run might currently be waiting on IO.

val run : ?after_init:(unit -> unit) -> t -> (unit, exn) result

Run the main loop of the server, listening on a socket described at the server's creation time, using new_thread to start a thread for each new client.

This returns Ok () if the server exits gracefully, or Error e if it exits with an error.

  • parameter after_init

    is called after the server starts listening. since 0.13 .

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 0.14
diff --git a/tiny_httpd/Tiny_httpd_core/Server/module-type-IO_BACKEND/index.html b/tiny_httpd/Tiny_httpd_core/Server/module-type-IO_BACKEND/index.html new file mode 100644 index 00000000..d78934b5 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Server/module-type-IO_BACKEND/index.html @@ -0,0 +1,2 @@ + +IO_BACKEND (tiny_httpd.Tiny_httpd_core.Server.IO_BACKEND)

Module type Server.IO_BACKEND

A backend that provides IO operations, network operations, etc.

This is used to decouple tiny_httpd from the scheduler/IO library used to actually open a TCP server and talk to clients. The classic way is based on Unix and blocking IOs, but it's also possible to use an OCaml 5 library using effects and non blocking IOs.

val init_addr : unit -> string

Initial TCP address

val init_port : unit -> int

Initial port

val get_time_s : unit -> float

Obtain the current timestamp in seconds.

val tcp_server : unit -> IO.TCP_server.builder

TCP server builder, to create servers that can listen on a port and handle clients.

diff --git a/tiny_httpd/Tiny_httpd_core/Server/module-type-SERVER_SENT_GENERATOR/index.html b/tiny_httpd/Tiny_httpd_core/Server/module-type-SERVER_SENT_GENERATOR/index.html new file mode 100644 index 00000000..07b9581f --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Server/module-type-SERVER_SENT_GENERATOR/index.html @@ -0,0 +1,8 @@ + +SERVER_SENT_GENERATOR (tiny_httpd.Tiny_httpd_core.Server.SERVER_SENT_GENERATOR)

Module type Server.SERVER_SENT_GENERATOR

A server-side function to generate of Server-sent events.

See the w3c page and this blog post.

  • since 0.9
val set_headers : Headers.t -> unit

Set headers of the response. This is not mandatory but if used at all, it must be called before any call to send_event (once events are sent the response is already sent too).

val send_event : + ?event:string -> + ?id:string -> + ?retry:string -> + data:string -> + unit -> + unit

Send an event from the server. If data is a multiline string, it will be sent on separate "data:" lines.

val close : unit -> unit

Close connection.

  • since 0.11
diff --git a/tiny_httpd/Tiny_httpd_core/Server/module-type-UPGRADE_HANDLER/index.html b/tiny_httpd/Tiny_httpd_core/Server/module-type-UPGRADE_HANDLER/index.html new file mode 100644 index 00000000..fe0d9e6f --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Server/module-type-UPGRADE_HANDLER/index.html @@ -0,0 +1,7 @@ + +UPGRADE_HANDLER (tiny_httpd.Tiny_httpd_core.Server.UPGRADE_HANDLER)

Module type Server.UPGRADE_HANDLER

Handler that upgrades to another protocol.

  • since NEXT_RELEASE
type handshake_state

Some specific state returned after handshake

val name : string

Name in the "upgrade" header

val handshake : unit Request.t -> (Headers.t * handshake_state, string) result

Perform the handshake and upgrade the connection. The returned code is 101 alongside these headers. In case the handshake fails, this only returns Error log_msg. The connection is closed without further ado.

val handle_connection : + Unix.sockaddr -> + handshake_state -> + IO.Input.t -> + IO.Output.t -> + unit

Take control of the connection and take it from ther.e

diff --git a/tiny_httpd/Tiny_httpd_core/Util/index.html b/tiny_httpd/Tiny_httpd_core/Util/index.html new file mode 100644 index 00000000..06848d8c --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/Util/index.html @@ -0,0 +1,2 @@ + +Util (tiny_httpd.Tiny_httpd_core.Util)

Module Tiny_httpd_core.Util

Some utils for writing web servers

  • since 0.2
val percent_encode : ?skip:(char -> bool) -> string -> string

Encode the string into a valid path following https://tools.ietf.org/html/rfc3986#section-2.1

  • parameter skip

    if provided, allows to preserve some characters, e.g. '/' in a path.

val percent_decode : string -> string option

Inverse operation of percent_encode. Can fail since some strings are not valid percent encodings.

val split_query : string -> string * string

Split a path between the path and the query

  • since 0.5
val split_on_slash : string -> string list

Split a string on '/', remove the trailing '/' if any.

  • since 0.6
val get_non_query_path : string -> string

get the part of the path that is not the query parameters.

  • since 0.5
val get_query : string -> string

Obtain the query part of a path.

  • since 0.4
val parse_query : string -> ((string * string) list, string) result

Parse a query as a list of '&' or ';' separated key=value pairs. The order might not be preserved.

  • since 0.3
val show_sockaddr : Unix.sockaddr -> string

Simple printer for socket addresses.

  • since NEXT_RELEASE
val is_ipv6_str : string -> bool

Is this string potentially an IPV6 address?

  • since NEXT_RELEASE
diff --git a/tiny_httpd/Tiny_httpd_core/index.html b/tiny_httpd/Tiny_httpd_core/index.html new file mode 100644 index 00000000..3ec6bbbb --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core (tiny_httpd.Tiny_httpd_core)

Module Tiny_httpd_core

module Atomic_ : sig ... end
module Buf : sig ... end

Simple buffer.

module Common_ : sig ... end
module Headers : sig ... end

Headers

module IO : sig ... end

IO abstraction.

module Log : sig ... end

Logging for tiny_httpd

module Meth : sig ... end

HTTP Methods

module Parse_ : sig ... end
module Pool : sig ... end

Resource pool.

module Request : sig ... end

Requests

module Response : sig ... end

Responses

module Response_code : sig ... end

Response Codes

module Route : sig ... end

Routing

module Server : sig ... end

HTTP server.

module Util : sig ... end
diff --git a/tiny_httpd/Tiny_httpd_core__Atomic_/index.html b/tiny_httpd/Tiny_httpd_core__Atomic_/index.html new file mode 100644 index 00000000..8e34f33f --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Atomic_/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Atomic_ (tiny_httpd.Tiny_httpd_core__Atomic_)

Module Tiny_httpd_core__Atomic_

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Buf/index.html b/tiny_httpd/Tiny_httpd_core__Buf/index.html new file mode 100644 index 00000000..25525be6 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Buf/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Buf (tiny_httpd.Tiny_httpd_core__Buf)

Module Tiny_httpd_core__Buf

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Headers/index.html b/tiny_httpd/Tiny_httpd_core__Headers/index.html new file mode 100644 index 00000000..fdb38f72 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Headers/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Headers (tiny_httpd.Tiny_httpd_core__Headers)

Module Tiny_httpd_core__Headers

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__IO/index.html b/tiny_httpd/Tiny_httpd_core__IO/index.html new file mode 100644 index 00000000..fbb77aa5 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__IO/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__IO (tiny_httpd.Tiny_httpd_core__IO)

Module Tiny_httpd_core__IO

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Log/index.html b/tiny_httpd/Tiny_httpd_core__Log/index.html new file mode 100644 index 00000000..397a70e2 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Log/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Log (tiny_httpd.Tiny_httpd_core__Log)

Module Tiny_httpd_core__Log

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Meth/index.html b/tiny_httpd/Tiny_httpd_core__Meth/index.html new file mode 100644 index 00000000..540f1c0f --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Meth/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Meth (tiny_httpd.Tiny_httpd_core__Meth)

Module Tiny_httpd_core__Meth

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Pool/index.html b/tiny_httpd/Tiny_httpd_core__Pool/index.html new file mode 100644 index 00000000..77a74291 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Pool/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Pool (tiny_httpd.Tiny_httpd_core__Pool)

Module Tiny_httpd_core__Pool

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Request/index.html b/tiny_httpd/Tiny_httpd_core__Request/index.html new file mode 100644 index 00000000..3309e829 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Request/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Request (tiny_httpd.Tiny_httpd_core__Request)

Module Tiny_httpd_core__Request

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Response/index.html b/tiny_httpd/Tiny_httpd_core__Response/index.html new file mode 100644 index 00000000..f4ad05c4 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Response/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Response (tiny_httpd.Tiny_httpd_core__Response)

Module Tiny_httpd_core__Response

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Response_code/index.html b/tiny_httpd/Tiny_httpd_core__Response_code/index.html new file mode 100644 index 00000000..2fd35d8e --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Response_code/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Response_code (tiny_httpd.Tiny_httpd_core__Response_code)

Module Tiny_httpd_core__Response_code

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Route/index.html b/tiny_httpd/Tiny_httpd_core__Route/index.html new file mode 100644 index 00000000..d5a4dad0 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Route/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Route (tiny_httpd.Tiny_httpd_core__Route)

Module Tiny_httpd_core__Route

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Server/index.html b/tiny_httpd/Tiny_httpd_core__Server/index.html new file mode 100644 index 00000000..5928c2d7 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Server/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Server (tiny_httpd.Tiny_httpd_core__Server)

Module Tiny_httpd_core__Server

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_core__Util/index.html b/tiny_httpd/Tiny_httpd_core__Util/index.html new file mode 100644 index 00000000..65580172 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_core__Util/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_core__Util (tiny_httpd.Tiny_httpd_core__Util)

Module Tiny_httpd_core__Util

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_dir/Embedded_fs/index.html b/tiny_httpd/Tiny_httpd_dir/Embedded_fs/index.html deleted file mode 100644 index c97f0cb2..00000000 --- a/tiny_httpd/Tiny_httpd_dir/Embedded_fs/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Embedded_fs (tiny_httpd.Tiny_httpd_dir.Embedded_fs)

Module Tiny_httpd_dir.Embedded_fs

An embedded file system, as a list of files with (relative) paths. This is useful in combination with the "tiny-httpd-mkfs" tool, which embeds the files it's given into a OCaml module.

  • since 0.12
type t

The pseudo-filesystem

val create : ?mtime:float -> unit -> t
val add_file : ?mtime:float -> t -> path:string -> string -> unit

Add file to the virtual file system.

  • raises Invalid_argument

    if the path contains '..' or if it tries to make a directory out of an existing path that is a file.

val to_vfs : t -> (module VFS)
diff --git a/tiny_httpd/Tiny_httpd_dir/index.html b/tiny_httpd/Tiny_httpd_dir/index.html deleted file mode 100644 index 6370ec20..00000000 --- a/tiny_httpd/Tiny_httpd_dir/index.html +++ /dev/null @@ -1,25 +0,0 @@ - -Tiny_httpd_dir (tiny_httpd.Tiny_httpd_dir)

Module Tiny_httpd_dir

Serving static content from directories

This module provides the same functionality as the "http_of_dir" tool. It exposes a directory (and its subdirectories), with the optional ability to delete or upload files.

  • since 0.11
type dir_behavior =
  1. | Index
    (*

    Redirect to index.html if present, else fails.

    *)
  2. | Lists
    (*

    Lists content of directory. Be careful of security implications.

    *)
  3. | Index_or_lists
    (*

    Redirect to index.html if present and lists content otherwise. This is useful for tilde ("~") directories and other per-user behavior, but be mindful of security implications

    *)
  4. | Forbidden
    (*

    Forbid access to directory. This is suited for serving assets, for example.

    *)

behavior of static directory.

This controls what happens when the user requests the path to a directory rather than a file.

type hidden

Type used to prevent users from building a config directly. Use default_config or config instead.

type config = {
  1. mutable download : bool;
    (*

    Is downloading files allowed?

    *)
  2. mutable dir_behavior : dir_behavior;
    (*

    Behavior when serving a directory and not a file

    *)
  3. mutable delete : bool;
    (*

    Is deleting a file allowed? (with method DELETE)

    *)
  4. mutable upload : bool;
    (*

    Is uploading a file allowed? (with method PUT)

    *)
  5. mutable max_upload_size : int;
    (*

    If upload is true, this is the maximum size in bytes for uploaded files.

    *)
  6. _rest : hidden;
    (*

    Just ignore this field.

    *)
}

configuration for static file handlers. This might get more fields over time.

val default_config : unit -> config

default configuration: - { download=true - ; dir_behavior=Forbidden - ; delete=false - ; upload=false - ; max_upload_size = 10 * 1024 * 1024 - }

val config : - ?download:bool -> - ?dir_behavior:dir_behavior -> - ?delete:bool -> - ?upload:bool -> - ?max_upload_size:int -> - unit -> - config

Build a config from default_config.

  • since 0.12
val add_dir_path : - config:config -> - dir:string -> - prefix:string -> - Tiny_httpd_server.t -> - unit

add_dirpath ~config ~dir ~prefix server adds route handle to the server to serve static files in dir when url starts with prefix, using the given configuration config.

module type VFS = sig ... end

Virtual file system.

val vfs_of_dir : string -> (module VFS)

vfs_of_dir dir makes a virtual file system that reads from the disk.

  • since 0.12
val add_vfs : - config:config -> - vfs:(module VFS) -> - prefix:string -> - Tiny_httpd_server.t -> - unit

Similar to add_dir_path but using a virtual file system instead.

  • since 0.12
module Embedded_fs : sig ... end

An embedded file system, as a list of files with (relative) paths. This is useful in combination with the "tiny-httpd-mkfs" tool, which embeds the files it's given into a OCaml module.

diff --git a/tiny_httpd/Tiny_httpd_dir/module-type-VFS/index.html b/tiny_httpd/Tiny_httpd_dir/module-type-VFS/index.html deleted file mode 100644 index 1099e3e2..00000000 --- a/tiny_httpd/Tiny_httpd_dir/module-type-VFS/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -VFS (tiny_httpd.Tiny_httpd_dir.VFS)

Module type Tiny_httpd_dir.VFS

Virtual file system.

This is used to emulate a file system from pure OCaml functions and data, e.g. for resources bundled inside the web server.

  • since 0.12
val descr : string

Description of the VFS

val is_directory : string -> bool
val contains : string -> bool

file_exists vfs path returns true if path points to a file or directory inside vfs.

val list_dir : string -> string array

List directory. This only returns basenames, the files need to be put in the directory path using Filename.concat.

val delete : string -> unit

Delete path

val create : string -> (bytes -> int -> int -> unit) * (unit -> unit)

Create a file and obtain a pair write, close

val read_file_content : string -> Tiny_httpd_stream.t

Read content of a file

val file_size : string -> int option

File size, e.g. using "stat"

val file_mtime : string -> float option

File modification time, e.g. using "stat"

diff --git a/tiny_httpd/Tiny_httpd_html/A/index.html b/tiny_httpd/Tiny_httpd_html/A/index.html new file mode 100644 index 00000000..763b39b3 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_html/A/index.html @@ -0,0 +1,2 @@ + +A (tiny_httpd.Tiny_httpd_html.A)

Module Tiny_httpd_html.A

Attributes.

This module contains combinator for the standard attributes. One can also just use a pair of strings.

Attributes.

This module contains combinator for the standard attributes. One can also just use a pair of strings.

type t = string -> string * string

Attribute builder

val accept : t

Attribute "accept".

val accept_charset : t

Attribute "accept-charset".

val accesskey : t

Attribute "accesskey".

val action : t

Attribute "action".

val align : t

Attribute "align".

val allow : t

Attribute "allow".

val alt : t

Attribute "alt".

val async : t

Attribute "async".

val autocapitalize : t

Attribute "autocapitalize".

val autocomplete : t

Attribute "autocomplete".

val autofocus : t

Attribute "autofocus".

val autoplay : t

Attribute "autoplay".

val buffered : t

Attribute "buffered".

val capture : t

Attribute "capture".

val challenge : t

Attribute "challenge".

val charset : t

Attribute "charset".

val checked : t

Attribute "checked".

val cite : t

Attribute "cite".

val class_ : t

Attribute "class".

val code : t

Attribute "code".

val codebase : t

Attribute "codebase".

val cols : t

Attribute "cols".

val colspan : t

Attribute "colspan".

val content : t

Attribute "content".

val contenteditable : t

Attribute "contenteditable".

val contextmenu : t

Attribute "contextmenu".

val controls : t

Attribute "controls".

val coords : t

Attribute "coords".

val crossorigin : t

Attribute "crossorigin".

val csp : t

Attribute "csp".

val data : t

Attribute "data".

val data_star : t

Attribute "data-*".

val datetime : t

Attribute "datetime".

val decoding : t

Attribute "decoding".

val default : t

Attribute "default".

val defer : t

Attribute "defer".

val dir : t

Attribute "dir".

val dirname : t

Attribute "dirname".

val disabled : t

Attribute "disabled".

val download : t

Attribute "download".

val draggable : t

Attribute "draggable".

val enctype : t

Attribute "enctype".

val enterkeyhint : t

Attribute "enterkeyhint".

val for_ : t

Attribute "for".

val form : t

Attribute "form".

val formaction : t

Attribute "formaction".

val formenctype : t

Attribute "formenctype".

val formmethod : t

Attribute "formmethod".

val formnovalidate : t

Attribute "formnovalidate".

val formtarget : t

Attribute "formtarget".

val headers : t

Attribute "headers".

val hidden : t

Attribute "hidden".

val high : t

Attribute "high".

val href : t

Attribute "href".

val hreflang : t

Attribute "hreflang".

val http_equiv : t

Attribute "http-equiv".

val icon : t

Attribute "icon".

val id : t

Attribute "id".

val importance : t

Attribute "importance".

val integrity : t

Attribute "integrity".

val ismap : t

Attribute "ismap".

val itemprop : t

Attribute "itemprop".

val keytype : t

Attribute "keytype".

val kind : t

Attribute "kind".

val label : t

Attribute "label".

val lang : t

Attribute "lang".

val language : t

Attribute "language".

val list : t

Attribute "list".

val loop : t

Attribute "loop".

val low : t

Attribute "low".

val manifest : t

Attribute "manifest".

val max : t

Attribute "max".

val maxlength : t

Attribute "maxlength".

val minlength : t

Attribute "minlength".

val media : t

Attribute "media".

val method_ : t

Attribute "method".

val min : t

Attribute "min".

val multiple : t

Attribute "multiple".

val muted : t

Attribute "muted".

val name : t

Attribute "name".

val novalidate : t

Attribute "novalidate".

val open_ : t

Attribute "open".

val optimum : t

Attribute "optimum".

val pattern : t

Attribute "pattern".

val ping : t

Attribute "ping".

val placeholder : t

Attribute "placeholder".

val poster : t

Attribute "poster".

val preload : t

Attribute "preload".

val radiogroup : t

Attribute "radiogroup".

val readonly : t

Attribute "readonly".

val referrerpolicy : t

Attribute "referrerpolicy".

val rel : t

Attribute "rel".

val required : t

Attribute "required".

val reversed : t

Attribute "reversed".

val rows : t

Attribute "rows".

val rowspan : t

Attribute "rowspan".

val sandbox : t

Attribute "sandbox".

val scope : t

Attribute "scope".

val scoped : t

Attribute "scoped".

val selected : t

Attribute "selected".

val shape : t

Attribute "shape".

val size : t

Attribute "size".

val sizes : t

Attribute "sizes".

val slot : t

Attribute "slot".

val span : t

Attribute "span".

val spellcheck : t

Attribute "spellcheck".

val src : t

Attribute "src".

val srcdoc : t

Attribute "srcdoc".

val srclang : t

Attribute "srclang".

val srcset : t

Attribute "srcset".

val start : t

Attribute "start".

val step : t

Attribute "step".

val style : t

Attribute "style".

val summary : t

Attribute "summary".

val tabindex : t

Attribute "tabindex".

val target : t

Attribute "target".

val title : t

Attribute "title".

val translate : t

Attribute "translate".

val text : t

Attribute "Text".

val type_ : t

Attribute "type".

val usemap : t

Attribute "usemap".

val value : t

Attribute "value".

val width : t

Attribute "width".

val wrap : t

Attribute "wrap".

diff --git a/tiny_httpd/Tiny_httpd_html/Out/index.html b/tiny_httpd/Tiny_httpd_html/Out/index.html new file mode 100644 index 00000000..3cfa5544 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_html/Out/index.html @@ -0,0 +1,2 @@ + +Out (tiny_httpd.Tiny_httpd_html.Out)

Module Tiny_httpd_html.Out

Output for HTML combinators.

This output type is used to produce a string reasonably efficiently from a tree of combinators.

NOTE: this is experimental and an unstable API.

  • since 0.12

Output for HTML combinators.

This output type is used to produce a string reasonably efficiently from a tree of combinators.

NOTE: this is experimental and an unstable API.

  • since 0.12
type t
val create_of_buffer : Stdlib.Buffer.t -> t
val create_of_out : Tiny_httpd_core.IO.Output.t -> t
val flush : t -> unit
val add_char : t -> char -> unit
val add_string : t -> string -> unit
val add_format_nl : t -> unit
val with_no_format_nl : t -> (unit -> 'a) -> 'a
diff --git a/tiny_httpd/Tiny_httpd_html/index.html b/tiny_httpd/Tiny_httpd_html/index.html index 603ac911..641856c2 100644 --- a/tiny_httpd/Tiny_httpd_html/index.html +++ b/tiny_httpd/Tiny_httpd_html/index.html @@ -1,2 +1,2 @@ -Tiny_httpd_html (tiny_httpd.Tiny_httpd_html)

Module Tiny_httpd_html

HTML combinators.

This module provides combinators to produce html. It doesn't enforce the well-formedness of the html, unlike Tyxml, but it's simple and should be reasonably efficient.

  • since 0.12
module IO = Tiny_httpd_io

Output for HTML combinators.

type attribute = string * string

An attribute, i.e. a key/value pair

type elt = Out.t -> unit

A html element. It is represented by its output function, so we can directly print it.

type void = ?if_:bool -> attribute list -> elt

Element without children.

type nary = ?if_:bool -> attribute list -> elt list -> elt

Element with children, represented as a list.

  • parameter if_

    if false, do not print anything (default true)

type sub_elt = [
  1. | `E of elt
  2. | `L of elt list
  3. | `S of elt Stdlib.Seq.t
  4. | `Nil
]

A chunk of sub-elements, possibly empty.

type nary' = ?if_:bool -> attribute list -> sub_elt list -> elt

Element with children, represented as a list of sub_elt to be flattened

  • parameter if_

    if false, do not print anything (default true)

val sub_e : elt -> sub_elt

Sub-element with a single element inside.

val sub_l : elt list -> sub_elt

Sub-element with a list of items inside.

val sub_seq : elt Stdlib.Seq.t -> sub_elt

Sub-element with a sequence (Seq.t) of items inside.

val seq_of_array : 'a array -> 'b Stdlib.Seq.t

Helper to build a Seq.t from an array.

val sub_empty : sub_elt

Sub-element with nothing inside. Useful in conditionals, when one decides not to emit a sub-element at all.

val txt : string -> elt

Emit a string value, which will be escaped.

val txtf : ('a, Stdlib.Format.formatter, unit, Out.t -> unit) format4 -> 'b

Formatted version of txt

val raw_html : string -> elt

Emit raw HTML. Caution, this can lead to injection vulnerabilities, never use with text that comes from untrusted users.

val area : void

tag "area", see mdn

val base : void

tag "base", see mdn

val br : void

tag "br", see mdn

val col : void

tag "col", see mdn

val embed : void

tag "embed", see mdn

val hr : void

tag "hr", see mdn

val img : void

tag "img", see mdn

val input : void

tag "input", see mdn

tag "link", see mdn

val menuitem : void

tag "menuitem", see mdn

val meta : void

tag "meta", see mdn

val param : void

tag "param", see mdn

val source : void

tag "source", see mdn

val track : void

tag "track", see mdn

val wbr : void

tag "wbr", see mdn

val a : nary

tag "a", see mdn

val a' : nary'

tag "a", see mdn

val abbr : nary

tag "abbr", see mdn

val abbr' : nary'

tag "abbr", see mdn

val address : nary

tag "address", see mdn

val address' : nary'

tag "address", see mdn

val article : nary

tag "article", see mdn

val article' : nary'

tag "article", see mdn

val aside : nary

tag "aside", see mdn

val aside' : nary'

tag "aside", see mdn

val audio : nary

tag "audio", see mdn

val audio' : nary'

tag "audio", see mdn

val b : nary

tag "b", see mdn

val b' : nary'

tag "b", see mdn

val bdi : nary

tag "bdi", see mdn

val bdi' : nary'

tag "bdi", see mdn

val bdo : nary

tag "bdo", see mdn

val bdo' : nary'

tag "bdo", see mdn

val blockquote : nary

tag "blockquote", see mdn

val blockquote' : nary'

tag "blockquote", see mdn

val body : nary

tag "body", see mdn

val body' : nary'

tag "body", see mdn

val button : nary

tag "button", see mdn

val button' : nary'

tag "button", see mdn

val canvas : nary

tag "canvas", see mdn

val canvas' : nary'

tag "canvas", see mdn

val caption : nary

tag "caption", see mdn

val caption' : nary'

tag "caption", see mdn

val cite : nary

tag "cite", see mdn

val cite' : nary'

tag "cite", see mdn

val code : nary

tag "code", see mdn

val code' : nary'

tag "code", see mdn

val colgroup : nary

tag "colgroup", see mdn

val colgroup' : nary'

tag "colgroup", see mdn

val data : nary

tag "data", see mdn

val data' : nary'

tag "data", see mdn

val datalist : nary

tag "datalist", see mdn

val datalist' : nary'

tag "datalist", see mdn

val dd : nary

tag "dd", see mdn

val dd' : nary'

tag "dd", see mdn

val del : nary

tag "del", see mdn

val del' : nary'

tag "del", see mdn

val details : nary

tag "details", see mdn

val details' : nary'

tag "details", see mdn

val dfn : nary

tag "dfn", see mdn

val dfn' : nary'

tag "dfn", see mdn

val dialog : nary

tag "dialog", see mdn

val dialog' : nary'

tag "dialog", see mdn

val div : nary

tag "div", see mdn

val div' : nary'

tag "div", see mdn

val dl : nary

tag "dl", see mdn

val dl' : nary'

tag "dl", see mdn

val dt : nary

tag "dt", see mdn

val dt' : nary'

tag "dt", see mdn

val em : nary

tag "em", see mdn

val em' : nary'

tag "em", see mdn

val fieldset : nary

tag "fieldset", see mdn

val fieldset' : nary'

tag "fieldset", see mdn

val figcaption : nary

tag "figcaption", see mdn

val figcaption' : nary'

tag "figcaption", see mdn

val figure : nary

tag "figure", see mdn

val figure' : nary'

tag "figure", see mdn

tag "footer", see mdn

val footer' : nary'

tag "footer", see mdn

val form : nary

tag "form", see mdn

val form' : nary'

tag "form", see mdn

val h1 : nary

tag "h1", see mdn

val h1' : nary'

tag "h1", see mdn

val h2 : nary

tag "h2", see mdn

val h2' : nary'

tag "h2", see mdn

val h3 : nary

tag "h3", see mdn

val h3' : nary'

tag "h3", see mdn

val h4 : nary

tag "h4", see mdn

val h4' : nary'

tag "h4", see mdn

val h5 : nary

tag "h5", see mdn

val h5' : nary'

tag "h5", see mdn

val h6 : nary

tag "h6", see mdn

val h6' : nary'

tag "h6", see mdn

val head : nary

tag "head", see mdn

val head' : nary'

tag "head", see mdn

val header : nary

tag "header", see mdn

val header' : nary'

tag "header", see mdn

val hgroup : nary

tag "hgroup", see mdn

val hgroup' : nary'

tag "hgroup", see mdn

val html : nary

tag "html", see mdn

val html' : nary'

tag "html", see mdn

val i : nary

tag "i", see mdn

val i' : nary'

tag "i", see mdn

val iframe : nary

tag "iframe", see mdn

val iframe' : nary'

tag "iframe", see mdn

val ins : nary

tag "ins", see mdn

val ins' : nary'

tag "ins", see mdn

val kbd : nary

tag "kbd", see mdn

val kbd' : nary'

tag "kbd", see mdn

val label : nary

tag "label", see mdn

val label' : nary'

tag "label", see mdn

val legend : nary

tag "legend", see mdn

val legend' : nary'

tag "legend", see mdn

val li : nary

tag "li", see mdn

val li' : nary'

tag "li", see mdn

val main : nary

tag "main", see mdn

val main' : nary'

tag "main", see mdn

val map : nary

tag "map", see mdn

val map' : nary'

tag "map", see mdn

val mark : nary

tag "mark", see mdn

val mark' : nary'

tag "mark", see mdn

val math : nary

tag "math", see mdn

val math' : nary'

tag "math", see mdn

val menu : nary

tag "menu", see mdn

val menu' : nary'

tag "menu", see mdn

val meter : nary

tag "meter", see mdn

val meter' : nary'

tag "meter", see mdn

val nav : nary

tag "nav", see mdn

val nav' : nary'

tag "nav", see mdn

val noscript : nary

tag "noscript", see mdn

val noscript' : nary'

tag "noscript", see mdn

val object_ : nary

tag "object", see mdn

val object_' : nary'

tag "object", see mdn

val ol : nary

tag "ol", see mdn

val ol' : nary'

tag "ol", see mdn

val optgroup : nary

tag "optgroup", see mdn

val optgroup' : nary'

tag "optgroup", see mdn

val option : nary

tag "option", see mdn

val option' : nary'

tag "option", see mdn

val output : nary

tag "output", see mdn

val output' : nary'

tag "output", see mdn

val p : nary

tag "p", see mdn

val p' : nary'

tag "p", see mdn

val picture : nary

tag "picture", see mdn

val picture' : nary'

tag "picture", see mdn

val pre : nary

tag "pre", see mdn

val pre' : nary'

tag "pre", see mdn

val progress : nary

tag "progress", see mdn

val progress' : nary'

tag "progress", see mdn

val q : nary

tag "q", see mdn

val q' : nary'

tag "q", see mdn

val rb : nary

tag "rb", see mdn

val rb' : nary'

tag "rb", see mdn

val rp : nary

tag "rp", see mdn

val rp' : nary'

tag "rp", see mdn

val rt : nary

tag "rt", see mdn

val rt' : nary'

tag "rt", see mdn

val rtc : nary

tag "rtc", see mdn

val rtc' : nary'

tag "rtc", see mdn

val ruby : nary

tag "ruby", see mdn

val ruby' : nary'

tag "ruby", see mdn

val s : nary

tag "s", see mdn

val s' : nary'

tag "s", see mdn

val samp : nary

tag "samp", see mdn

val samp' : nary'

tag "samp", see mdn

val script : nary

tag "script", see mdn

val script' : nary'

tag "script", see mdn

val section : nary

tag "section", see mdn

val section' : nary'

tag "section", see mdn

val select : nary

tag "select", see mdn

val select' : nary'

tag "select", see mdn

val slot : nary

tag "slot", see mdn

val slot' : nary'

tag "slot", see mdn

val small : nary

tag "small", see mdn

val small' : nary'

tag "small", see mdn

val span : nary

tag "span", see mdn

val span' : nary'

tag "span", see mdn

val strong : nary

tag "strong", see mdn

val strong' : nary'

tag "strong", see mdn

val style : nary

tag "style", see mdn

val style' : nary'

tag "style", see mdn

val sub : nary

tag "sub", see mdn

val sub' : nary'

tag "sub", see mdn

val summary : nary

tag "summary", see mdn

val summary' : nary'

tag "summary", see mdn

val sup : nary

tag "sup", see mdn

val sup' : nary'

tag "sup", see mdn

val svg : nary

tag "svg", see mdn

val svg' : nary'

tag "svg", see mdn

val table : nary

tag "table", see mdn

val table' : nary'

tag "table", see mdn

val tbody : nary

tag "tbody", see mdn

val tbody' : nary'

tag "tbody", see mdn

val td : nary

tag "td", see mdn

val td' : nary'

tag "td", see mdn

val template : nary

tag "template", see mdn

val template' : nary'

tag "template", see mdn

val textarea : nary

tag "textarea", see mdn

val textarea' : nary'

tag "textarea", see mdn

val tfoot : nary

tag "tfoot", see mdn

val tfoot' : nary'

tag "tfoot", see mdn

val th : nary

tag "th", see mdn

val th' : nary'

tag "th", see mdn

val thead : nary

tag "thead", see mdn

val thead' : nary'

tag "thead", see mdn

val time : nary

tag "time", see mdn

val time' : nary'

tag "time", see mdn

val title : nary

tag "title", see mdn

val title' : nary'

tag "title", see mdn

val tr : nary

tag "tr", see mdn

val tr' : nary'

tag "tr", see mdn

val u : nary

tag "u", see mdn

val u' : nary'

tag "u", see mdn

val ul : nary

tag "ul", see mdn

val ul' : nary'

tag "ul", see mdn

val var : nary

tag "var", see mdn

val var' : nary'

tag "var", see mdn

val video : nary

tag "video", see mdn

val video' : nary'

tag "video", see mdn

Attributes.

val to_output : ?top:bool -> elt -> IO.Output.t -> unit

Write an HTML element to this output.

  • parameter top

    if true, add DOCTYPE at the beginning. The top element should then be a "html" tag.

  • since 0.14
val to_string : ?top:bool -> elt -> string

Convert a HTML element to a string.

  • parameter top

    if true, add DOCTYPE at the beginning. The top element should then be a "html" tag.

val to_string_l : elt list -> string

Convert a list of HTML elements to a string. This is designed for fragments of HTML that are to be injected inside a bigger context, as it's invalid to have multiple elements at the toplevel of a HTML document.

val to_string_top : elt -> string
val to_out_channel_top : elt -> IO.Output.t -> unit

Write a toplevel element to an output channel.

  • since 0.14
val to_writer : ?top:bool -> elt -> IO.Writer.t

Produce a streaming writer from this HTML element.

  • parameter top

    if true, add a DOCTYPE. See to_out_channel.

  • since 0.14
val to_stream : elt -> Tiny_httpd_stream.t

Convert a HTML element to a stream. This might just convert it to a string first, do not assume it to be more efficient.

+Tiny_httpd_html (tiny_httpd.Tiny_httpd_html)

Module Tiny_httpd_html

HTML combinators.

This module provides combinators to produce html. It doesn't enforce the well-formedness of the html, unlike Tyxml, but it's simple and should be reasonably efficient.

  • since 0.12
module Out : sig ... end

Output for HTML combinators.

type attribute = string * string

An attribute, i.e. a key/value pair

type elt = Out.t -> unit

A html element. It is represented by its output function, so we can directly print it.

type void = ?if_:bool -> attribute list -> elt

Element without children.

type nary = ?if_:bool -> attribute list -> elt list -> elt

Element with children, represented as a list.

  • parameter if_

    if false, do not print anything (default true)

type sub_elt = [
  1. | `E of elt
  2. | `L of elt list
  3. | `S of elt Stdlib.Seq.t
  4. | `Nil
]

A chunk of sub-elements, possibly empty.

type nary' = ?if_:bool -> attribute list -> sub_elt list -> elt

Element with children, represented as a list of sub_elt to be flattened

  • parameter if_

    if false, do not print anything (default true)

val sub_e : elt -> sub_elt

Sub-element with a single element inside.

val sub_l : elt list -> sub_elt

Sub-element with a list of items inside.

val sub_seq : elt Stdlib.Seq.t -> sub_elt

Sub-element with a sequence (Seq.t) of items inside.

val seq_of_array : 'a array -> 'b Stdlib.Seq.t

Helper to build a Seq.t from an array.

val sub_empty : sub_elt

Sub-element with nothing inside. Useful in conditionals, when one decides not to emit a sub-element at all.

val txt : string -> elt

Emit a string value, which will be escaped.

val txtf : ('a, Stdlib.Format.formatter, unit, Out.t -> unit) format4 -> 'b

Formatted version of txt

val raw_html : string -> elt

Emit raw HTML. Caution, this can lead to injection vulnerabilities, never use with text that comes from untrusted users.

val area : void

tag "area", see mdn

val base : void

tag "base", see mdn

val br : void

tag "br", see mdn

val col : void

tag "col", see mdn

val embed : void

tag "embed", see mdn

val hr : void

tag "hr", see mdn

val img : void

tag "img", see mdn

val input : void

tag "input", see mdn

tag "link", see mdn

val menuitem : void

tag "menuitem", see mdn

val meta : void

tag "meta", see mdn

val param : void

tag "param", see mdn

val source : void

tag "source", see mdn

val track : void

tag "track", see mdn

val wbr : void

tag "wbr", see mdn

val a : nary

tag "a", see mdn

val a' : nary'

tag "a", see mdn

val abbr : nary

tag "abbr", see mdn

val abbr' : nary'

tag "abbr", see mdn

val address : nary

tag "address", see mdn

val address' : nary'

tag "address", see mdn

val article : nary

tag "article", see mdn

val article' : nary'

tag "article", see mdn

val aside : nary

tag "aside", see mdn

val aside' : nary'

tag "aside", see mdn

val audio : nary

tag "audio", see mdn

val audio' : nary'

tag "audio", see mdn

val b : nary

tag "b", see mdn

val b' : nary'

tag "b", see mdn

val bdi : nary

tag "bdi", see mdn

val bdi' : nary'

tag "bdi", see mdn

val bdo : nary

tag "bdo", see mdn

val bdo' : nary'

tag "bdo", see mdn

val blockquote : nary

tag "blockquote", see mdn

val blockquote' : nary'

tag "blockquote", see mdn

val body : nary

tag "body", see mdn

val body' : nary'

tag "body", see mdn

val button : nary

tag "button", see mdn

val button' : nary'

tag "button", see mdn

val canvas : nary

tag "canvas", see mdn

val canvas' : nary'

tag "canvas", see mdn

val caption : nary

tag "caption", see mdn

val caption' : nary'

tag "caption", see mdn

val cite : nary

tag "cite", see mdn

val cite' : nary'

tag "cite", see mdn

val code : nary

tag "code", see mdn

val code' : nary'

tag "code", see mdn

val colgroup : nary

tag "colgroup", see mdn

val colgroup' : nary'

tag "colgroup", see mdn

val data : nary

tag "data", see mdn

val data' : nary'

tag "data", see mdn

val datalist : nary

tag "datalist", see mdn

val datalist' : nary'

tag "datalist", see mdn

val dd : nary

tag "dd", see mdn

val dd' : nary'

tag "dd", see mdn

val del : nary

tag "del", see mdn

val del' : nary'

tag "del", see mdn

val details : nary

tag "details", see mdn

val details' : nary'

tag "details", see mdn

val dfn : nary

tag "dfn", see mdn

val dfn' : nary'

tag "dfn", see mdn

val dialog : nary

tag "dialog", see mdn

val dialog' : nary'

tag "dialog", see mdn

val div : nary

tag "div", see mdn

val div' : nary'

tag "div", see mdn

val dl : nary

tag "dl", see mdn

val dl' : nary'

tag "dl", see mdn

val dt : nary

tag "dt", see mdn

val dt' : nary'

tag "dt", see mdn

val em : nary

tag "em", see mdn

val em' : nary'

tag "em", see mdn

val fieldset : nary

tag "fieldset", see mdn

val fieldset' : nary'

tag "fieldset", see mdn

val figcaption : nary

tag "figcaption", see mdn

val figcaption' : nary'

tag "figcaption", see mdn

val figure : nary

tag "figure", see mdn

val figure' : nary'

tag "figure", see mdn

tag "footer", see mdn

val footer' : nary'

tag "footer", see mdn

val form : nary

tag "form", see mdn

val form' : nary'

tag "form", see mdn

val h1 : nary

tag "h1", see mdn

val h1' : nary'

tag "h1", see mdn

val h2 : nary

tag "h2", see mdn

val h2' : nary'

tag "h2", see mdn

val h3 : nary

tag "h3", see mdn

val h3' : nary'

tag "h3", see mdn

val h4 : nary

tag "h4", see mdn

val h4' : nary'

tag "h4", see mdn

val h5 : nary

tag "h5", see mdn

val h5' : nary'

tag "h5", see mdn

val h6 : nary

tag "h6", see mdn

val h6' : nary'

tag "h6", see mdn

val head : nary

tag "head", see mdn

val head' : nary'

tag "head", see mdn

val header : nary

tag "header", see mdn

val header' : nary'

tag "header", see mdn

val hgroup : nary

tag "hgroup", see mdn

val hgroup' : nary'

tag "hgroup", see mdn

val html : nary

tag "html", see mdn

val html' : nary'

tag "html", see mdn

val i : nary

tag "i", see mdn

val i' : nary'

tag "i", see mdn

val iframe : nary

tag "iframe", see mdn

val iframe' : nary'

tag "iframe", see mdn

val ins : nary

tag "ins", see mdn

val ins' : nary'

tag "ins", see mdn

val kbd : nary

tag "kbd", see mdn

val kbd' : nary'

tag "kbd", see mdn

val label : nary

tag "label", see mdn

val label' : nary'

tag "label", see mdn

val legend : nary

tag "legend", see mdn

val legend' : nary'

tag "legend", see mdn

val li : nary

tag "li", see mdn

val li' : nary'

tag "li", see mdn

val main : nary

tag "main", see mdn

val main' : nary'

tag "main", see mdn

val map : nary

tag "map", see mdn

val map' : nary'

tag "map", see mdn

val mark : nary

tag "mark", see mdn

val mark' : nary'

tag "mark", see mdn

val math : nary

tag "math", see mdn

val math' : nary'

tag "math", see mdn

val menu : nary

tag "menu", see mdn

val menu' : nary'

tag "menu", see mdn

val meter : nary

tag "meter", see mdn

val meter' : nary'

tag "meter", see mdn

val nav : nary

tag "nav", see mdn

val nav' : nary'

tag "nav", see mdn

val noscript : nary

tag "noscript", see mdn

val noscript' : nary'

tag "noscript", see mdn

val object_ : nary

tag "object", see mdn

val object_' : nary'

tag "object", see mdn

val ol : nary

tag "ol", see mdn

val ol' : nary'

tag "ol", see mdn

val optgroup : nary

tag "optgroup", see mdn

val optgroup' : nary'

tag "optgroup", see mdn

val option : nary

tag "option", see mdn

val option' : nary'

tag "option", see mdn

val output : nary

tag "output", see mdn

val output' : nary'

tag "output", see mdn

val p : nary

tag "p", see mdn

val p' : nary'

tag "p", see mdn

val picture : nary

tag "picture", see mdn

val picture' : nary'

tag "picture", see mdn

val pre : nary

tag "pre", see mdn

val pre' : nary'

tag "pre", see mdn

val progress : nary

tag "progress", see mdn

val progress' : nary'

tag "progress", see mdn

val q : nary

tag "q", see mdn

val q' : nary'

tag "q", see mdn

val rb : nary

tag "rb", see mdn

val rb' : nary'

tag "rb", see mdn

val rp : nary

tag "rp", see mdn

val rp' : nary'

tag "rp", see mdn

val rt : nary

tag "rt", see mdn

val rt' : nary'

tag "rt", see mdn

val rtc : nary

tag "rtc", see mdn

val rtc' : nary'

tag "rtc", see mdn

val ruby : nary

tag "ruby", see mdn

val ruby' : nary'

tag "ruby", see mdn

val s : nary

tag "s", see mdn

val s' : nary'

tag "s", see mdn

val samp : nary

tag "samp", see mdn

val samp' : nary'

tag "samp", see mdn

val script : nary

tag "script", see mdn

val script' : nary'

tag "script", see mdn

val section : nary

tag "section", see mdn

val section' : nary'

tag "section", see mdn

val select : nary

tag "select", see mdn

val select' : nary'

tag "select", see mdn

val slot : nary

tag "slot", see mdn

val slot' : nary'

tag "slot", see mdn

val small : nary

tag "small", see mdn

val small' : nary'

tag "small", see mdn

val span : nary

tag "span", see mdn

val span' : nary'

tag "span", see mdn

val strong : nary

tag "strong", see mdn

val strong' : nary'

tag "strong", see mdn

val style : nary

tag "style", see mdn

val style' : nary'

tag "style", see mdn

val sub : nary

tag "sub", see mdn

val sub' : nary'

tag "sub", see mdn

val summary : nary

tag "summary", see mdn

val summary' : nary'

tag "summary", see mdn

val sup : nary

tag "sup", see mdn

val sup' : nary'

tag "sup", see mdn

val svg : nary

tag "svg", see mdn

val svg' : nary'

tag "svg", see mdn

val table : nary

tag "table", see mdn

val table' : nary'

tag "table", see mdn

val tbody : nary

tag "tbody", see mdn

val tbody' : nary'

tag "tbody", see mdn

val td : nary

tag "td", see mdn

val td' : nary'

tag "td", see mdn

val template : nary

tag "template", see mdn

val template' : nary'

tag "template", see mdn

val textarea : nary

tag "textarea", see mdn

val textarea' : nary'

tag "textarea", see mdn

val tfoot : nary

tag "tfoot", see mdn

val tfoot' : nary'

tag "tfoot", see mdn

val th : nary

tag "th", see mdn

val th' : nary'

tag "th", see mdn

val thead : nary

tag "thead", see mdn

val thead' : nary'

tag "thead", see mdn

val time : nary

tag "time", see mdn

val time' : nary'

tag "time", see mdn

val title : nary

tag "title", see mdn

val title' : nary'

tag "title", see mdn

val tr : nary

tag "tr", see mdn

val tr' : nary'

tag "tr", see mdn

val u : nary

tag "u", see mdn

val u' : nary'

tag "u", see mdn

val ul : nary

tag "ul", see mdn

val ul' : nary'

tag "ul", see mdn

val var : nary

tag "var", see mdn

val var' : nary'

tag "var", see mdn

val video : nary

tag "video", see mdn

val video' : nary'

tag "video", see mdn

module A : sig ... end

Attributes.

val to_output : ?top:bool -> elt -> Tiny_httpd_core.IO.Output.t -> unit

Write an HTML element to this output.

  • parameter top

    if true, add DOCTYPE at the beginning. The top element should then be a "html" tag.

  • since 0.14
val to_string : ?top:bool -> elt -> string

Convert a HTML element to a string.

  • parameter top

    if true, add DOCTYPE at the beginning. The top element should then be a "html" tag.

val to_string_l : elt list -> string

Convert a list of HTML elements to a string. This is designed for fragments of HTML that are to be injected inside a bigger context, as it's invalid to have multiple elements at the toplevel of a HTML document.

val to_string_top : elt -> string
val to_out_channel_top : elt -> Tiny_httpd_core.IO.Output.t -> unit

Write a toplevel element to an output channel.

  • since 0.14
val to_writer : ?top:bool -> elt -> Tiny_httpd_core.IO.Writer.t

Produce a streaming writer from this HTML element.

  • parameter top

    if true, add a DOCTYPE. See to_out_channel.

  • since 0.14
val to_stream : elt -> Tiny_httpd_core.IO.Input.t

Convert a HTML element to a stream. This might just convert it to a string first, do not assume it to be more efficient.

diff --git a/tiny_httpd/Tiny_httpd_html_/A/index.html b/tiny_httpd/Tiny_httpd_html_/A/index.html deleted file mode 100644 index 8ee4720a..00000000 --- a/tiny_httpd/Tiny_httpd_html_/A/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -A (tiny_httpd.Tiny_httpd_html_.A)

Module Tiny_httpd_html_.A

Attributes.

This module contains combinator for the standard attributes. One can also just use a pair of strings.

type t = string -> attribute

Attribute builder

val accept : t

Attribute "accept".

val accept_charset : t

Attribute "accept-charset".

val accesskey : t

Attribute "accesskey".

val action : t

Attribute "action".

val align : t

Attribute "align".

val allow : t

Attribute "allow".

val alt : t

Attribute "alt".

val async : t

Attribute "async".

val autocapitalize : t

Attribute "autocapitalize".

val autocomplete : t

Attribute "autocomplete".

val autofocus : t

Attribute "autofocus".

val autoplay : t

Attribute "autoplay".

val buffered : t

Attribute "buffered".

val capture : t

Attribute "capture".

val challenge : t

Attribute "challenge".

val charset : t

Attribute "charset".

val checked : t

Attribute "checked".

val cite : t

Attribute "cite".

val class_ : t

Attribute "class".

val code : t

Attribute "code".

val codebase : t

Attribute "codebase".

val cols : t

Attribute "cols".

val colspan : t

Attribute "colspan".

val content : t

Attribute "content".

val contenteditable : t

Attribute "contenteditable".

val contextmenu : t

Attribute "contextmenu".

val controls : t

Attribute "controls".

val coords : t

Attribute "coords".

val crossorigin : t

Attribute "crossorigin".

val csp : t

Attribute "csp".

val data : t

Attribute "data".

val data_star : t

Attribute "data-*".

val datetime : t

Attribute "datetime".

val decoding : t

Attribute "decoding".

val default : t

Attribute "default".

val defer : t

Attribute "defer".

val dir : t

Attribute "dir".

val dirname : t

Attribute "dirname".

val disabled : t

Attribute "disabled".

val download : t

Attribute "download".

val draggable : t

Attribute "draggable".

val enctype : t

Attribute "enctype".

val enterkeyhint : t

Attribute "enterkeyhint".

val for_ : t

Attribute "for".

val form : t

Attribute "form".

val formaction : t

Attribute "formaction".

val formenctype : t

Attribute "formenctype".

val formmethod : t

Attribute "formmethod".

val formnovalidate : t

Attribute "formnovalidate".

val formtarget : t

Attribute "formtarget".

val headers : t

Attribute "headers".

val hidden : t

Attribute "hidden".

val high : t

Attribute "high".

val href : t

Attribute "href".

val hreflang : t

Attribute "hreflang".

val http_equiv : t

Attribute "http-equiv".

val icon : t

Attribute "icon".

val id : t

Attribute "id".

val importance : t

Attribute "importance".

val integrity : t

Attribute "integrity".

val ismap : t

Attribute "ismap".

val itemprop : t

Attribute "itemprop".

val keytype : t

Attribute "keytype".

val kind : t

Attribute "kind".

val label : t

Attribute "label".

val lang : t

Attribute "lang".

val language : t

Attribute "language".

val list : t

Attribute "list".

val loop : t

Attribute "loop".

val low : t

Attribute "low".

val manifest : t

Attribute "manifest".

val max : t

Attribute "max".

val maxlength : t

Attribute "maxlength".

val minlength : t

Attribute "minlength".

val media : t

Attribute "media".

val method_ : t

Attribute "method".

val min : t

Attribute "min".

val multiple : t

Attribute "multiple".

val muted : t

Attribute "muted".

val name : t

Attribute "name".

val novalidate : t

Attribute "novalidate".

val open_ : t

Attribute "open".

val optimum : t

Attribute "optimum".

val pattern : t

Attribute "pattern".

val ping : t

Attribute "ping".

val placeholder : t

Attribute "placeholder".

val poster : t

Attribute "poster".

val preload : t

Attribute "preload".

val radiogroup : t

Attribute "radiogroup".

val readonly : t

Attribute "readonly".

val referrerpolicy : t

Attribute "referrerpolicy".

val rel : t

Attribute "rel".

val required : t

Attribute "required".

val reversed : t

Attribute "reversed".

val rows : t

Attribute "rows".

val rowspan : t

Attribute "rowspan".

val sandbox : t

Attribute "sandbox".

val scope : t

Attribute "scope".

val scoped : t

Attribute "scoped".

val selected : t

Attribute "selected".

val shape : t

Attribute "shape".

val size : t

Attribute "size".

val sizes : t

Attribute "sizes".

val slot : t

Attribute "slot".

val span : t

Attribute "span".

val spellcheck : t

Attribute "spellcheck".

val src : t

Attribute "src".

val srcdoc : t

Attribute "srcdoc".

val srclang : t

Attribute "srclang".

val srcset : t

Attribute "srcset".

val start : t

Attribute "start".

val step : t

Attribute "step".

val style : t

Attribute "style".

val summary : t

Attribute "summary".

val tabindex : t

Attribute "tabindex".

val target : t

Attribute "target".

val title : t

Attribute "title".

val translate : t

Attribute "translate".

val text : t

Attribute "Text".

val type_ : t

Attribute "type".

val usemap : t

Attribute "usemap".

val value : t

Attribute "value".

val width : t

Attribute "width".

val wrap : t

Attribute "wrap".

diff --git a/tiny_httpd/Tiny_httpd_html_/Out/index.html b/tiny_httpd/Tiny_httpd_html_/Out/index.html deleted file mode 100644 index 7d32dec1..00000000 --- a/tiny_httpd/Tiny_httpd_html_/Out/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Out (tiny_httpd.Tiny_httpd_html_.Out)

Module Tiny_httpd_html_.Out

Output for HTML combinators.

This output type is used to produce a string reasonably efficiently from a tree of combinators.

NOTE: this is experimental and an unstable API.

  • since 0.12
type t
val create_of_buffer : Stdlib.Buffer.t -> t
val create_of_out : Tiny_httpd_io.Output.t -> t
val flush : t -> unit
val add_char : t -> char -> unit
val add_string : t -> string -> unit
val add_format_nl : t -> unit
val with_no_format_nl : t -> (unit -> 'a) -> 'a
diff --git a/tiny_httpd/Tiny_httpd_html_/index.html b/tiny_httpd/Tiny_httpd_html_/index.html deleted file mode 100644 index c077b957..00000000 --- a/tiny_httpd/Tiny_httpd_html_/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Tiny_httpd_html_ (tiny_httpd.Tiny_httpd_html_)

Module Tiny_httpd_html_

module Out : sig ... end

Output for HTML combinators.

type attribute = string * string

An attribute, i.e. a key/value pair

type elt = Out.t -> unit

A html element. It is represented by its output function, so we can directly print it.

type void = ?if_:bool -> attribute list -> elt

Element without children.

type nary = ?if_:bool -> attribute list -> elt list -> elt

Element with children, represented as a list.

  • parameter if_

    if false, do not print anything (default true)

type sub_elt = [
  1. | `E of elt
  2. | `L of elt list
  3. | `S of elt Stdlib.Seq.t
  4. | `Nil
]

A chunk of sub-elements, possibly empty.

type nary' = ?if_:bool -> attribute list -> sub_elt list -> elt

Element with children, represented as a list of sub_elt to be flattened

  • parameter if_

    if false, do not print anything (default true)

val sub_e : elt -> sub_elt

Sub-element with a single element inside.

val sub_l : elt list -> sub_elt

Sub-element with a list of items inside.

val sub_seq : elt Stdlib.Seq.t -> sub_elt

Sub-element with a sequence (Seq.t) of items inside.

val seq_of_array : 'a array -> 'b Stdlib.Seq.t

Helper to build a Seq.t from an array.

val sub_empty : sub_elt

Sub-element with nothing inside. Useful in conditionals, when one decides not to emit a sub-element at all.

val txt : string -> elt

Emit a string value, which will be escaped.

val txtf : ('a, Stdlib.Format.formatter, unit, Out.t -> unit) format4 -> 'b

Formatted version of txt

val raw_html : string -> elt

Emit raw HTML. Caution, this can lead to injection vulnerabilities, never use with text that comes from untrusted users.

val area : void

tag "area", see mdn

val base : void

tag "base", see mdn

val br : void

tag "br", see mdn

val col : void

tag "col", see mdn

val embed : void

tag "embed", see mdn

val hr : void

tag "hr", see mdn

val img : void

tag "img", see mdn

val input : void

tag "input", see mdn

tag "link", see mdn

val menuitem : void

tag "menuitem", see mdn

val meta : void

tag "meta", see mdn

val param : void

tag "param", see mdn

val source : void

tag "source", see mdn

val track : void

tag "track", see mdn

val wbr : void

tag "wbr", see mdn

val a : nary

tag "a", see mdn

val a' : nary'

tag "a", see mdn

val abbr : nary

tag "abbr", see mdn

val abbr' : nary'

tag "abbr", see mdn

val address : nary

tag "address", see mdn

val address' : nary'

tag "address", see mdn

val article : nary

tag "article", see mdn

val article' : nary'

tag "article", see mdn

val aside : nary

tag "aside", see mdn

val aside' : nary'

tag "aside", see mdn

val audio : nary

tag "audio", see mdn

val audio' : nary'

tag "audio", see mdn

val b : nary

tag "b", see mdn

val b' : nary'

tag "b", see mdn

val bdi : nary

tag "bdi", see mdn

val bdi' : nary'

tag "bdi", see mdn

val bdo : nary

tag "bdo", see mdn

val bdo' : nary'

tag "bdo", see mdn

val blockquote : nary

tag "blockquote", see mdn

val blockquote' : nary'

tag "blockquote", see mdn

val body : nary

tag "body", see mdn

val body' : nary'

tag "body", see mdn

val button : nary

tag "button", see mdn

val button' : nary'

tag "button", see mdn

val canvas : nary

tag "canvas", see mdn

val canvas' : nary'

tag "canvas", see mdn

val caption : nary

tag "caption", see mdn

val caption' : nary'

tag "caption", see mdn

val cite : nary

tag "cite", see mdn

val cite' : nary'

tag "cite", see mdn

val code : nary

tag "code", see mdn

val code' : nary'

tag "code", see mdn

val colgroup : nary

tag "colgroup", see mdn

val colgroup' : nary'

tag "colgroup", see mdn

val data : nary

tag "data", see mdn

val data' : nary'

tag "data", see mdn

val datalist : nary

tag "datalist", see mdn

val datalist' : nary'

tag "datalist", see mdn

val dd : nary

tag "dd", see mdn

val dd' : nary'

tag "dd", see mdn

val del : nary

tag "del", see mdn

val del' : nary'

tag "del", see mdn

val details : nary

tag "details", see mdn

val details' : nary'

tag "details", see mdn

val dfn : nary

tag "dfn", see mdn

val dfn' : nary'

tag "dfn", see mdn

val dialog : nary

tag "dialog", see mdn

val dialog' : nary'

tag "dialog", see mdn

val div : nary

tag "div", see mdn

val div' : nary'

tag "div", see mdn

val dl : nary

tag "dl", see mdn

val dl' : nary'

tag "dl", see mdn

val dt : nary

tag "dt", see mdn

val dt' : nary'

tag "dt", see mdn

val em : nary

tag "em", see mdn

val em' : nary'

tag "em", see mdn

val fieldset : nary

tag "fieldset", see mdn

val fieldset' : nary'

tag "fieldset", see mdn

val figcaption : nary

tag "figcaption", see mdn

val figcaption' : nary'

tag "figcaption", see mdn

val figure : nary

tag "figure", see mdn

val figure' : nary'

tag "figure", see mdn

tag "footer", see mdn

val footer' : nary'

tag "footer", see mdn

val form : nary

tag "form", see mdn

val form' : nary'

tag "form", see mdn

val h1 : nary

tag "h1", see mdn

val h1' : nary'

tag "h1", see mdn

val h2 : nary

tag "h2", see mdn

val h2' : nary'

tag "h2", see mdn

val h3 : nary

tag "h3", see mdn

val h3' : nary'

tag "h3", see mdn

val h4 : nary

tag "h4", see mdn

val h4' : nary'

tag "h4", see mdn

val h5 : nary

tag "h5", see mdn

val h5' : nary'

tag "h5", see mdn

val h6 : nary

tag "h6", see mdn

val h6' : nary'

tag "h6", see mdn

val head : nary

tag "head", see mdn

val head' : nary'

tag "head", see mdn

val header : nary

tag "header", see mdn

val header' : nary'

tag "header", see mdn

val hgroup : nary

tag "hgroup", see mdn

val hgroup' : nary'

tag "hgroup", see mdn

val html : nary

tag "html", see mdn

val html' : nary'

tag "html", see mdn

val i : nary

tag "i", see mdn

val i' : nary'

tag "i", see mdn

val iframe : nary

tag "iframe", see mdn

val iframe' : nary'

tag "iframe", see mdn

val ins : nary

tag "ins", see mdn

val ins' : nary'

tag "ins", see mdn

val kbd : nary

tag "kbd", see mdn

val kbd' : nary'

tag "kbd", see mdn

val label : nary

tag "label", see mdn

val label' : nary'

tag "label", see mdn

val legend : nary

tag "legend", see mdn

val legend' : nary'

tag "legend", see mdn

val li : nary

tag "li", see mdn

val li' : nary'

tag "li", see mdn

val main : nary

tag "main", see mdn

val main' : nary'

tag "main", see mdn

val map : nary

tag "map", see mdn

val map' : nary'

tag "map", see mdn

val mark : nary

tag "mark", see mdn

val mark' : nary'

tag "mark", see mdn

val math : nary

tag "math", see mdn

val math' : nary'

tag "math", see mdn

val menu : nary

tag "menu", see mdn

val menu' : nary'

tag "menu", see mdn

val meter : nary

tag "meter", see mdn

val meter' : nary'

tag "meter", see mdn

val nav : nary

tag "nav", see mdn

val nav' : nary'

tag "nav", see mdn

val noscript : nary

tag "noscript", see mdn

val noscript' : nary'

tag "noscript", see mdn

val object_ : nary

tag "object", see mdn

val object_' : nary'

tag "object", see mdn

val ol : nary

tag "ol", see mdn

val ol' : nary'

tag "ol", see mdn

val optgroup : nary

tag "optgroup", see mdn

val optgroup' : nary'

tag "optgroup", see mdn

val option : nary

tag "option", see mdn

val option' : nary'

tag "option", see mdn

val output : nary

tag "output", see mdn

val output' : nary'

tag "output", see mdn

val p : nary

tag "p", see mdn

val p' : nary'

tag "p", see mdn

val picture : nary

tag "picture", see mdn

val picture' : nary'

tag "picture", see mdn

val pre : nary

tag "pre", see mdn

val pre' : nary'

tag "pre", see mdn

val progress : nary

tag "progress", see mdn

val progress' : nary'

tag "progress", see mdn

val q : nary

tag "q", see mdn

val q' : nary'

tag "q", see mdn

val rb : nary

tag "rb", see mdn

val rb' : nary'

tag "rb", see mdn

val rp : nary

tag "rp", see mdn

val rp' : nary'

tag "rp", see mdn

val rt : nary

tag "rt", see mdn

val rt' : nary'

tag "rt", see mdn

val rtc : nary

tag "rtc", see mdn

val rtc' : nary'

tag "rtc", see mdn

val ruby : nary

tag "ruby", see mdn

val ruby' : nary'

tag "ruby", see mdn

val s : nary

tag "s", see mdn

val s' : nary'

tag "s", see mdn

val samp : nary

tag "samp", see mdn

val samp' : nary'

tag "samp", see mdn

val script : nary

tag "script", see mdn

val script' : nary'

tag "script", see mdn

val section : nary

tag "section", see mdn

val section' : nary'

tag "section", see mdn

val select : nary

tag "select", see mdn

val select' : nary'

tag "select", see mdn

val slot : nary

tag "slot", see mdn

val slot' : nary'

tag "slot", see mdn

val small : nary

tag "small", see mdn

val small' : nary'

tag "small", see mdn

val span : nary

tag "span", see mdn

val span' : nary'

tag "span", see mdn

val strong : nary

tag "strong", see mdn

val strong' : nary'

tag "strong", see mdn

val style : nary

tag "style", see mdn

val style' : nary'

tag "style", see mdn

val sub : nary

tag "sub", see mdn

val sub' : nary'

tag "sub", see mdn

val summary : nary

tag "summary", see mdn

val summary' : nary'

tag "summary", see mdn

val sup : nary

tag "sup", see mdn

val sup' : nary'

tag "sup", see mdn

val svg : nary

tag "svg", see mdn

val svg' : nary'

tag "svg", see mdn

val table : nary

tag "table", see mdn

val table' : nary'

tag "table", see mdn

val tbody : nary

tag "tbody", see mdn

val tbody' : nary'

tag "tbody", see mdn

val td : nary

tag "td", see mdn

val td' : nary'

tag "td", see mdn

val template : nary

tag "template", see mdn

val template' : nary'

tag "template", see mdn

val textarea : nary

tag "textarea", see mdn

val textarea' : nary'

tag "textarea", see mdn

val tfoot : nary

tag "tfoot", see mdn

val tfoot' : nary'

tag "tfoot", see mdn

val th : nary

tag "th", see mdn

val th' : nary'

tag "th", see mdn

val thead : nary

tag "thead", see mdn

val thead' : nary'

tag "thead", see mdn

val time : nary

tag "time", see mdn

val time' : nary'

tag "time", see mdn

val title : nary

tag "title", see mdn

val title' : nary'

tag "title", see mdn

val tr : nary

tag "tr", see mdn

val tr' : nary'

tag "tr", see mdn

val u : nary

tag "u", see mdn

val u' : nary'

tag "u", see mdn

val ul : nary

tag "ul", see mdn

val ul' : nary'

tag "ul", see mdn

val var : nary

tag "var", see mdn

val var' : nary'

tag "var", see mdn

val video : nary

tag "video", see mdn

val video' : nary'

tag "video", see mdn

module A : sig ... end

Attributes.

diff --git a/tiny_httpd/Tiny_httpd_html__/index.html b/tiny_httpd/Tiny_httpd_html__/index.html new file mode 100644 index 00000000..07b7a45d --- /dev/null +++ b/tiny_httpd/Tiny_httpd_html__/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_html__ (tiny_httpd.Tiny_httpd_html__)

Module Tiny_httpd_html__

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_html__Html_/index.html b/tiny_httpd/Tiny_httpd_html__Html_/index.html new file mode 100644 index 00000000..2de02081 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_html__Html_/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_html__Html_ (tiny_httpd.Tiny_httpd_html__Html_)

Module Tiny_httpd_html__Html_

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_io/Input/index.html b/tiny_httpd/Tiny_httpd_io/Input/index.html deleted file mode 100644 index 20b2d40d..00000000 --- a/tiny_httpd/Tiny_httpd_io/Input/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Input (tiny_httpd.Tiny_httpd_io.Input)

Module Tiny_httpd_io.Input

Input channel (byte source)

type t = {
  1. input : bytes -> int -> int -> int;
    (*

    Read into the slice. Returns 0 only if the channel is closed.

    *)
  2. close : unit -> unit;
    (*

    Close the input. Must be idempotent.

    *)
}

An input channel, i.e an incoming stream of bytes.

This can be a string, an int_channel, an Unix.file_descr, a decompression wrapper around another input channel, etc.

val of_in_channel : ?close_noerr:bool -> in_channel -> t
val of_unix_fd : ?close_noerr:bool -> closed:bool ref -> Unix.file_descr -> t
val of_slice : bytes -> int -> int -> t
val input : t -> bytes -> int -> int -> int

Read into the given slice.

  • returns

    the number of bytes read, 0 means end of input.

val really_input : t -> bytes -> int -> int -> unit

Read exactly len bytes.

  • raises End_of_file

    if the input did not contain enough data.

val close : t -> unit

Close the channel.

val append : t -> t -> t
diff --git a/tiny_httpd/Tiny_httpd_io/Output/index.html b/tiny_httpd/Tiny_httpd_io/Output/index.html deleted file mode 100644 index 8abcbcae..00000000 --- a/tiny_httpd/Tiny_httpd_io/Output/index.html +++ /dev/null @@ -1,7 +0,0 @@ - -Output (tiny_httpd.Tiny_httpd_io.Output)

Module Tiny_httpd_io.Output

Output channel (byte sink)

type t = {
  1. output_char : char -> unit;
    (*

    Output a single char

    *)
  2. output : bytes -> int -> int -> unit;
    (*

    Output slice

    *)
  3. flush : unit -> unit;
    (*

    Flush underlying buffer

    *)
  4. close : unit -> unit;
    (*

    Close the output. Must be idempotent.

    *)
}

An output channel, ie. a place into which we can write bytes.

This can be a Buffer.t, an out_channel, a Unix.file_descr, etc.

val of_unix_fd : - ?close_noerr:bool -> - closed:bool ref -> - buf:Buf.t -> - Unix.file_descr -> - t
val of_out_channel : ?close_noerr:bool -> out_channel -> t

of_out_channel oc wraps the channel into a Output.t.

  • parameter close_noerr

    if true, then closing the result uses close_out_noerr instead of close_out to close oc

val of_buffer : Stdlib.Buffer.t -> t

of_buffer buf is an output channel that writes directly into buf. flush and close have no effect.

val output_char : t -> char -> unit

Output the buffer slice into this channel

val output : t -> bytes -> int -> int -> unit

Output the buffer slice into this channel

val output_string : t -> string -> unit
val close : t -> unit

Close the channel.

val flush : t -> unit

Flush (ie. force write) any buffered bytes.

val output_buf : t -> Buf.t -> unit
val chunk_encoding : ?buf:Buf.t -> close_rec:bool -> t -> t

chunk_encoding oc makes a new channel that outputs its content into oc in chunk encoding form.

  • parameter close_rec

    if true, closing the result will also close oc

  • parameter buf

    a buffer used to accumulate data into chunks. Chunks are emitted when buf's size gets over a certain threshold, or when flush is called.

diff --git a/tiny_httpd/Tiny_httpd_io/TCP_server/index.html b/tiny_httpd/Tiny_httpd_io/TCP_server/index.html deleted file mode 100644 index b4264f51..00000000 --- a/tiny_httpd/Tiny_httpd_io/TCP_server/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -TCP_server (tiny_httpd.Tiny_httpd_io.TCP_server)

Module Tiny_httpd_io.TCP_server

A TCP server abstraction.

type conn_handler = {
  1. handle : client_addr:Unix.sockaddr -> Input.t -> Output.t -> unit;
    (*

    Handle client connection

    *)
}
type t = {
  1. endpoint : unit -> string * int;
    (*

    Endpoint we listen on. This can only be called from within serve.

    *)
  2. active_connections : unit -> int;
    (*

    Number of connections currently active

    *)
  3. running : unit -> bool;
    (*

    Is the server currently running?

    *)
  4. stop : unit -> unit;
    (*

    Ask the server to stop. This might not take effect immediately, and is idempotent. After this server.running() must return false.

    *)
}

A running TCP server.

This contains some functions that provide information about the running server, including whether it's active (as opposed to stopped), a function to stop it, and statistics about the number of connections.

type builder = {
  1. serve : after_init:(t -> unit) -> handle:conn_handler -> unit -> unit;
    (*

    Blocking call to listen for incoming connections and handle them. Uses the connection handler handle to handle individual client connections in individual threads/fibers/tasks.

    • parameter after_init

      is called once with the server after the server has started.

    *)
}

A TCP server builder implementation.

Calling builder.serve ~after_init ~handle () starts a new TCP server on an unspecified endpoint (most likely coming from the function returning this builder) and returns the running server.

diff --git a/tiny_httpd/Tiny_httpd_io/Writer/index.html b/tiny_httpd/Tiny_httpd_io/Writer/index.html deleted file mode 100644 index 5d0b2145..00000000 --- a/tiny_httpd/Tiny_httpd_io/Writer/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Writer (tiny_httpd.Tiny_httpd_io.Writer)

Module Tiny_httpd_io.Writer

A writer abstraction.

type t = {
  1. write : Output.t -> unit;
}

Writer.

A writer is a push-based stream of bytes. Give it an output channel and it will write the bytes in it.

This is useful for responses: an http endpoint can return a writer as its response's body; the writer is given access to the connection to the client and can write into it as if it were a regular out_channel, including controlling calls to flush. Tiny_httpd will convert these writes into valid HTTP chunks.

  • since 0.14
val make : write:(Output.t -> unit) -> unit -> t
val write : Output.t -> t -> unit

Write into the channel.

val empty : t

Empty writer, will output 0 bytes.

val of_string : string -> t

A writer that just emits the bytes from the given string.

diff --git a/tiny_httpd/Tiny_httpd_io/index.html b/tiny_httpd/Tiny_httpd_io/index.html deleted file mode 100644 index 81b8f98f..00000000 --- a/tiny_httpd/Tiny_httpd_io/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Tiny_httpd_io (tiny_httpd.Tiny_httpd_io)

Module Tiny_httpd_io

IO abstraction.

We abstract IO so we can support classic unix blocking IOs with threads, and modern async IO with Eio.

NOTE: experimental.

  • since 0.14
module Buf = Tiny_httpd_buf
module Input : sig ... end

Input channel (byte source)

module Output : sig ... end

Output channel (byte sink)

module Writer : sig ... end

A writer abstraction.

module TCP_server : sig ... end

A TCP server abstraction.

diff --git a/tiny_httpd/Tiny_httpd_log/index.html b/tiny_httpd/Tiny_httpd_log/index.html deleted file mode 100644 index 22c65b87..00000000 --- a/tiny_httpd/Tiny_httpd_log/index.html +++ /dev/null @@ -1,8 +0,0 @@ - -Tiny_httpd_log (tiny_httpd.Tiny_httpd_log)

Module Tiny_httpd_log

Logging for tiny_httpd

val info : - ((('a, Stdlib.Format.formatter, unit, unit) format4 -> 'a) -> unit) -> - unit
val debug : - ((('a, Stdlib.Format.formatter, unit, unit) format4 -> 'a) -> unit) -> - unit
val error : - ((('a, Stdlib.Format.formatter, unit, unit) format4 -> 'a) -> unit) -> - unit
val setup : debug:bool -> unit -> unit

Setup and enable logging. This should only ever be used in executables, not libraries.

  • parameter debug

    if true, set logging to debug (otherwise info)

val dummy : bool
diff --git a/tiny_httpd/Tiny_httpd_prometheus/index.html b/tiny_httpd/Tiny_httpd_prometheus/index.html index a1e92371..5dac806d 100644 --- a/tiny_httpd/Tiny_httpd_prometheus/index.html +++ b/tiny_httpd/Tiny_httpd_prometheus/index.html @@ -1,2 +1,2 @@ -Tiny_httpd_prometheus (tiny_httpd.Tiny_httpd_prometheus)

Module Tiny_httpd_prometheus

Expose metrics over HTTP in the prometheus format.

This sub-library tiny_httpd.prometheus provides definitions for counters, gauges, and histogram, and endpoints to expose them for Prometheus to scrape them.

  • since 0.16
type tags = (string * string) list
module Registry : sig ... end

Registry for metrics.

val global : Registry.t
module Counter : sig ... end

Counters

module Gauge : sig ... end

Gauges

module Histogram : sig ... end
val http_middleware : Registry.t -> Tiny_httpd.Middleware.t

Middleware to get basic metrics about HTTP requests

val add_route_to_server : Tiny_httpd.t -> Registry.t -> unit

Add a "/metrics" route to the server

val instrument_server : Tiny_httpd.t -> Registry.t -> unit

Add middleware and route

module GC_metrics : sig ... end
+Tiny_httpd_prometheus (tiny_httpd.Tiny_httpd_prometheus)

Module Tiny_httpd_prometheus

Expose metrics over HTTP in the prometheus format.

This sub-library tiny_httpd.prometheus provides definitions for counters, gauges, and histogram, and endpoints to expose them for Prometheus to scrape them.

  • since 0.16
type tags = (string * string) list
module Registry : sig ... end

Registry for metrics.

val global : Registry.t
module Counter : sig ... end

Counters

module Gauge : sig ... end

Gauges

module Histogram : sig ... end

Middleware to get basic metrics about HTTP requests

val add_route_to_server : Tiny_httpd_core.Server.t -> Registry.t -> unit

Add a "/metrics" route to the server

val instrument_server : Tiny_httpd_core.Server.t -> Registry.t -> unit

Add middleware and route

module GC_metrics : sig ... end
diff --git a/tiny_httpd/Tiny_httpd_server/Headers/index.html b/tiny_httpd/Tiny_httpd_server/Headers/index.html deleted file mode 100644 index 2d1dbba0..00000000 --- a/tiny_httpd/Tiny_httpd_server/Headers/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Headers (tiny_httpd.Tiny_httpd_server.Headers)

Module Tiny_httpd_server.Headers

type t = (string * string) list

The header files of a request or response.

Neither the key nor the value can contain '\r' or '\n'. See https://tools.ietf.org/html/rfc7230#section-3.2

val empty : t

Empty list of headers.

  • since 0.5
val get : ?f:(string -> string) -> string -> t -> string option

get k headers looks for the header field with key k.

  • parameter f

    if provided, will transform the value before it is returned.

val set : string -> string -> t -> t

set k v headers sets the key k to value v. It erases any previous entry for k

val remove : string -> t -> t

Remove the key from the headers, if present.

val contains : string -> t -> bool

Is there a header with the given key?

val pp : Stdlib.Format.formatter -> t -> unit

Pretty print the headers.

diff --git a/tiny_httpd/Tiny_httpd_server/Meth/index.html b/tiny_httpd/Tiny_httpd_server/Meth/index.html deleted file mode 100644 index d99fa09f..00000000 --- a/tiny_httpd/Tiny_httpd_server/Meth/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Meth (tiny_httpd.Tiny_httpd_server.Meth)

Module Tiny_httpd_server.Meth

type t = [
  1. | `GET
  2. | `PUT
  3. | `POST
  4. | `HEAD
  5. | `DELETE
  6. | `OPTIONS
]

A HTTP method. For now we only handle a subset of these.

See https://tools.ietf.org/html/rfc7231#section-4

val pp : Stdlib.Format.formatter -> t -> unit
val to_string : t -> string
diff --git a/tiny_httpd/Tiny_httpd_server/Middleware/index.html b/tiny_httpd/Tiny_httpd_server/Middleware/index.html deleted file mode 100644 index 9235ec5f..00000000 --- a/tiny_httpd/Tiny_httpd_server/Middleware/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Middleware (tiny_httpd.Tiny_httpd_server.Middleware)

Module Tiny_httpd_server.Middleware

type handler = byte_stream Request.t -> resp:(Response.t -> unit) -> unit

Handlers are functions returning a response to a request. The response can be delayed, hence the use of a continuation as the resp parameter.

type t = handler -> handler

A middleware is a handler transformation.

It takes the existing handler h, and returns a new one which, given a query, modify it or log it before passing it to h, or fail. It can also log or modify or drop the response.

val nil : t

Trivial middleware that does nothing.

diff --git a/tiny_httpd/Tiny_httpd_server/Request/index.html b/tiny_httpd/Tiny_httpd_server/Request/index.html deleted file mode 100644 index 61e5ed9f..00000000 --- a/tiny_httpd/Tiny_httpd_server/Request/index.html +++ /dev/null @@ -1,6 +0,0 @@ - -Request (tiny_httpd.Tiny_httpd_server.Request)

Module Tiny_httpd_server.Request

type 'body t = private {
  1. meth : Meth.t;
    (*

    HTTP method for this request.

    *)
  2. host : string;
    (*

    Host header, mandatory. It can also be found in headers.

    *)
  3. client_addr : Unix.sockaddr;
    (*

    Client address. Available since 0.14.

    *)
  4. headers : Headers.t;
    (*

    List of headers.

    *)
  5. http_version : int * int;
    (*

    HTTP version. This should be either 1, 0 or 1, 1.

    *)
  6. path : string;
    (*

    Full path of the requested URL.

    *)
  7. path_components : string list;
    (*

    Components of the path of the requested URL.

    *)
  8. query : (string * string) list;
    (*

    Query part of the requested URL.

    *)
  9. body : 'body;
    (*

    Body of the request.

    *)
  10. start_time : float;
    (*

    Obtained via get_time_s in create

    • since 0.11
    *)
}

A request with method, path, host, headers, and a body, sent by a client.

The body is polymorphic because the request goes through several transformations. First it has no body, as only the request and headers are read; then it has a stream body; then the body might be entirely read as a string via read_body_full.

  • since 0.6 The field [query] was added and contains the query parameters in ["?foo=bar,x=y"]
  • since 0.6 The field [path_components] is the part of the path that precedes [query] and is split on ["/"].
  • since 0.11 the type is a private alias
  • since 0.11 the field [start_time] was added
val pp : Stdlib.Format.formatter -> string t -> unit

Pretty print the request and its body. The exact format of this printing is not specified.

val pp_ : Stdlib.Format.formatter -> _ t -> unit

Pretty print the request without its body. The exact format of this printing is not specified.

val headers : _ t -> Headers.t

List of headers of the request, including "Host".

val get_header : ?f:(string -> string) -> _ t -> string -> string option

get_header req h looks up header h in req. It returns None if the header is not present. This is case insensitive and should be used rather than looking up h verbatim in headers.

val get_header_int : _ t -> string -> int option

Same as get_header but also performs a string to integer conversion.

val set_header : string -> string -> 'a t -> 'a t

set_header k v req sets k: v in the request req's headers.

val remove_header : string -> 'a t -> 'a t

Remove one instance of this header.

  • since NEXT_RELEASE
val update_headers : (Headers.t -> Headers.t) -> 'a t -> 'a t

Modify headers using the given function.

  • since 0.11
val set_body : 'a -> _ t -> 'a t

set_body b req returns a new query whose body is b.

  • since 0.11
val host : _ t -> string

Host field of the request. It also appears in the headers.

val client_addr : _ t -> Unix.sockaddr

Client address of the request.

  • since 0.16
val meth : _ t -> Meth.t

Method for the request.

val path : _ t -> string

Request path.

val query : _ t -> (string * string) list

Decode the query part of the path field.

  • since 0.4
val body : 'b t -> 'b

Request body, possibly empty.

val start_time : _ t -> float

time stamp (from Unix.gettimeofday) after parsing the first line of the request

  • since 0.11
val limit_body_size : max_size:int -> byte_stream t -> byte_stream t

Limit the body size to max_size bytes, or return a 413 error.

  • since 0.3
val read_body_full : - ?buf:Tiny_httpd_buf.t -> - ?buf_size:int -> - byte_stream t -> - string t

Read the whole body into a string. Potentially blocking.

  • parameter buf_size

    initial size of underlying buffer (since 0.11)

  • parameter buf

    the initial buffer (since 0.14)

diff --git a/tiny_httpd/Tiny_httpd_server/Response/index.html b/tiny_httpd/Tiny_httpd_server/Response/index.html deleted file mode 100644 index c2020022..00000000 --- a/tiny_httpd/Tiny_httpd_server/Response/index.html +++ /dev/null @@ -1,26 +0,0 @@ - -Response (tiny_httpd.Tiny_httpd_server.Response)

Module Tiny_httpd_server.Response

type body = [
  1. | `String of string
  2. | `Stream of byte_stream
  3. | `Writer of Tiny_httpd_io.Writer.t
  4. | `Void
]

Body of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events notably).

  • `String str replies with a body set to this string, and a known content-length.
  • `Stream str replies with a body made from this string, using chunked encoding.
  • `Void replies with no body.
  • `Writer w replies with a body created by the writer w, using a chunked encoding. It is available since 0.14.
type t = private {
  1. code : Response_code.t;
    (*

    HTTP response code. See Response_code.

    *)
  2. headers : Headers.t;
    (*

    Headers of the reply. Some will be set by Tiny_httpd automatically.

    *)
  3. body : body;
    (*

    Body of the response. Can be empty.

    *)
}

A response to send back to a client.

val set_body : body -> t -> t

Set the body of the response.

  • since 0.11
val set_header : string -> string -> t -> t

Set a header.

  • since 0.11
val update_headers : (Headers.t -> Headers.t) -> t -> t

Modify headers.

  • since 0.11
val remove_header : string -> t -> t

Remove one instance of this header.

  • since NEXT_RELEASE
val set_headers : Headers.t -> t -> t

Set all headers.

  • since 0.11
val set_code : Response_code.t -> t -> t

Set the response code.

  • since 0.11
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> t

Make a response from its raw components, with a string body. Use "" to not send a body at all.

val make_raw_stream : - ?headers:Headers.t -> - code:Response_code.t -> - byte_stream -> - t

Same as make_raw but with a stream body. The body will be sent with the chunked transfer-encoding.

val make_void : ?headers:Headers.t -> code:int -> unit -> t

Return a response without a body at all.

  • since 0.13
val make : - ?headers:Headers.t -> - ?code:int -> - (body, Response_code.t * string) result -> - t

make r turns a result into a response.

  • make (Ok body) replies with 200 and the body.
  • make (Error (code,msg)) replies with the given error code and message as body.
val make_string : - ?headers:Headers.t -> - ?code:int -> - (string, Response_code.t * string) result -> - t

Same as make but with a string body.

val make_writer : - ?headers:Headers.t -> - ?code:int -> - (Tiny_httpd_io.Writer.t, Response_code.t * string) result -> - t

Same as make but with a writer body.

val make_stream : - ?headers:Headers.t -> - ?code:int -> - (byte_stream, Response_code.t * string) result -> - t

Same as make but with a stream body.

val fail : - ?headers:Headers.t -> - code:int -> - ('a, unit, string, t) format4 -> - 'a

Make the current request fail with the given code and message. Example: fail ~code:404 "oh noes, %s not found" "waldo".

val fail_raise : code:int -> ('a, unit, string, 'b) format4 -> 'a

Similar to fail but raises an exception that exits the current handler. This should not be used outside of a (path) handler. Example: fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()

val pp : Stdlib.Format.formatter -> t -> unit

Pretty print the response. The exact format is not specified.

diff --git a/tiny_httpd/Tiny_httpd_server/Response_code/index.html b/tiny_httpd/Tiny_httpd_server/Response_code/index.html deleted file mode 100644 index a3ec9933..00000000 --- a/tiny_httpd/Tiny_httpd_server/Response_code/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Response_code (tiny_httpd.Tiny_httpd_server.Response_code)

Module Tiny_httpd_server.Response_code

type t = int

A standard HTTP code.

https://tools.ietf.org/html/rfc7231#section-6

val ok : t

The code 200

val not_found : t

The code 404

val descr : t -> string

A description of some of the error codes. NOTE: this is not complete (yet).

val is_success : t -> bool

is_success code is true iff code is in the 2xx or 3xx range.

  • since NEXT_RELEASE
diff --git a/tiny_httpd/Tiny_httpd_server/Route/index.html b/tiny_httpd/Tiny_httpd_server/Route/index.html deleted file mode 100644 index 0f85cfb6..00000000 --- a/tiny_httpd/Tiny_httpd_server/Route/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Route (tiny_httpd.Tiny_httpd_server.Route)

Module Tiny_httpd_server.Route

type ('a, 'b) comp

An atomic component of a path

type ('a, 'b) t

A route, composed of path components

val int : (int -> 'a, 'a) comp

Matches an integer.

val string : (string -> 'a, 'a) comp

Matches a string not containing '/' and binds it as is.

val string_urlencoded : (string -> 'a, 'a) comp

Matches a URL-encoded string, and decodes it.

val exact : string -> ('a, 'a) comp

exact "s" matches "s" and nothing else.

val return : ('a, 'a) t

Matches the empty path.

val rest_of_path : (string -> 'a, 'a) t

Matches a string, even containing '/'. This will match the entirety of the remaining route.

  • since 0.7
val rest_of_path_urlencoded : (string -> 'a, 'a) t

Matches a string, even containing '/', an URL-decode it. This will match the entirety of the remaining route.

  • since 0.7
val (@/) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t

comp / route matches "foo/bar/…" iff comp matches "foo", and route matches "bar/…".

val exact_path : string -> ('a, 'b) t -> ('a, 'b) t

exact_path "foo/bar/..." r is equivalent to exact "foo" @/ exact "bar" @/ ... @/ r

  • since 0.11 *
val pp : Stdlib.Format.formatter -> (_, _) t -> unit

Print the route.

  • since 0.7
val to_string : (_, _) t -> string

Print the route.

  • since 0.7
diff --git a/tiny_httpd/Tiny_httpd_server/index.html b/tiny_httpd/Tiny_httpd_server/index.html deleted file mode 100644 index 5c97a568..00000000 --- a/tiny_httpd/Tiny_httpd_server/index.html +++ /dev/null @@ -1,53 +0,0 @@ - -Tiny_httpd_server (tiny_httpd.Tiny_httpd_server)

Module Tiny_httpd_server

HTTP server.

This module implements a very simple, basic HTTP/1.1 server using blocking IOs and threads.

It is possible to use a thread pool, see create's argument new_thread.

  • since 0.13
type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t

HTTP Methods

module Meth : sig ... end

Headers

Headers are metadata associated with a request or response.

module Headers : sig ... end

Requests

Requests are sent by a client, e.g. a web browser or cURL. From the point of view of the server, they're inputs.

module Request : sig ... end

Response Codes

module Response_code : sig ... end

Responses

Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t

module Response : sig ... end

Routing

Basic type-safe routing of handlers based on URL paths. This is optional, it is possible to only define the root handler with something like Routes.

  • since 0.6
module Route : sig ... end

Middlewares

A middleware can be inserted in a handler to modify or observe its behavior.

  • since 0.11
module Middleware : sig ... end

Main Server type

type t

A HTTP server. See create for more details.

val create : - ?masksigpipe:bool -> - ?max_connections:int -> - ?timeout:float -> - ?buf_size:int -> - ?get_time_s:(unit -> float) -> - ?new_thread:((unit -> unit) -> unit) -> - ?addr:string -> - ?port:int -> - ?sock:Unix.file_descr -> - ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> - unit -> - t

Create a new webserver using UNIX abstractions.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter masksigpipe

    if true, block the signal Sys.sigpipe which otherwise tends to kill client threads when they try to write on broken sockets. Default: true.

  • parameter buf_size

    size for buffers (since 0.11)

  • parameter new_thread

    a function used to spawn a new thread to handle a new client connection. By default it is Thread.create but one could use a thread pool instead. See for example this use of moonpool.

  • parameter max_connections

    maximum number of simultaneous connections.

  • parameter timeout

    connection is closed if the socket does not do read or write for the amount of second. Default: 0.0 which means no timeout. timeout is not recommended when using proxy.

  • parameter addr

    address (IPv4 or IPv6) to listen on. Default "127.0.0.1".

  • parameter port

    to listen on. Default 8080.

  • parameter sock

    an existing socket given to the server to listen on, e.g. by systemd on Linux (or launchd on macOS). If passed in, this socket will be used instead of the addr and port. If not passed in, those will be used. This parameter exists since 0.10.

  • parameter get_time_s

    obtain the current timestamp in seconds. This parameter exists since 0.11.

module type IO_BACKEND = sig ... end

A backend that provides IO operations, network operations, etc.

val create_from : - ?buf_size:int -> - ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> - backend:(module IO_BACKEND) -> - unit -> - t

Create a new webserver using provided backend.

The server will not do anything until run is called on it. Before starting the server, one can use add_path_handler and set_top_handler to specify how to handle incoming requests.

  • parameter buf_size

    size for buffers (since 0.11)

  • since 0.14
val addr : t -> string

Address on which the server listens.

val is_ipv6 : t -> bool

is_ipv6 server returns true iff the address of the server is an IPv6 address.

  • since 0.3
val port : t -> int

Port on which the server listens. Note that this might be different than the port initially given if the port was 0 (meaning that the OS picks a port for us).

val active_connections : t -> int

Number of currently active connections.

val add_decode_request_cb : - t -> - (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) -> - unit

Add a callback for every request. The callback can provide a stream transformer and a new request (with modified headers, typically). A possible use is to handle decompression by looking for a Transfer-Encoding header and returning a stream transformer that decompresses on the fly.

val add_encode_response_cb : - t -> - (unit Request.t -> Response.t -> Response.t option) -> - unit

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. The callback is given the query with only its headers, as well as the current response.

val add_middleware : - stage:[ `Encoding | `Stage of int ] -> - t -> - Middleware.t -> - unit

Add a middleware to every request/response pair.

  • parameter stage

    specify when middleware applies. Encoding comes first (outermost layer), then stages in increasing order.

  • raises Invalid_argument

    if stage is `Stage n where n < 1

  • since 0.11

Request handlers

val set_top_handler : t -> (byte_stream Request.t -> Response.t) -> unit

Setup a handler called by default.

This handler is called with any request not accepted by any handler installed via add_path_handler. 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 0.14 . Use Request.read_body_full to read the body into a string if needed.

val add_route_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - ?middlewares:Middleware.t list -> - ?meth:Meth.t -> - t -> - ('a, string Request.t -> Response.t) Route.t -> - 'a -> - unit

add_route_handler server Route.(exact "path" @/ string @/ int @/ return) f calls f "foo" 42 request when a request with path "path/foo/42/" is received.

Note that the handlers are called in the reverse order of their addition, so the last registered handler can override previously registered ones.

  • parameter meth

    if provided, only accept requests with the given method. Typically one could react to `GET or `PUT.

  • parameter accept

    should return Ok() if the given request (before its body is read) should be accepted, Error (code,message) if it's to be rejected (e.g. because its content is too big, or for some permission error). See the http_of_dir program for an example of how to use accept to filter uploads that are too large before the upload even starts. The default always returns Ok(), i.e. it accepts all requests.

  • since 0.6
val add_route_handler_stream : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - ?middlewares:Middleware.t list -> - ?meth:Meth.t -> - t -> - ('a, byte_stream Request.t -> Response.t) Route.t -> - 'a -> - unit

Similar to add_route_handler, but where the body of the request is a stream of bytes that has not been read yet. This is useful when one wants to stream the body directly into a parser, json decoder (such as Jsonm) or into a file.

  • since 0.6

Server-sent events

EXPERIMENTAL: this API is not stable yet.

module type SERVER_SENT_GENERATOR = sig ... end

A server-side function to generate of Server-sent events.

type server_sent_generator = (module SERVER_SENT_GENERATOR)

Server-sent event generator. This generates events that are forwarded to the client (e.g. the browser).

  • since 0.9
val add_route_server_sent_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - t -> - ('a, string Request.t -> server_sent_generator -> unit) Route.t -> - 'a -> - unit

Add a handler on an endpoint, that serves server-sent events.

The callback is given a generator that can be used to send events as it pleases. The connection is always closed by the client, and the accepted method is always GET. This will set the header "content-type" to "text/event-stream" automatically and reply with a 200 immediately. See server_sent_generator for more details.

This handler stays on the original thread (it is synchronous).

  • since 0.9

Upgrade handlers

These handlers upgrade the connection to another protocol.

  • since NEXT_RELEASE
module type UPGRADE_HANDLER = sig ... end

Handler that upgrades to another protocol.

type upgrade_handler = (module UPGRADE_HANDLER)
  • since NEXT_RELEASE
val add_upgrade_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - t -> - ('a, upgrade_handler) Route.t -> - 'a -> - unit

Run the server

val running : t -> bool

Is the server running?

  • since 0.14
val stop : t -> unit

Ask the server to stop. This might not have an immediate effect as run might currently be waiting on IO.

val run : ?after_init:(unit -> unit) -> t -> (unit, exn) result

Run the main loop of the server, listening on a socket described at the server's creation time, using new_thread to start a thread for each new client.

This returns Ok () if the server exits gracefully, or Error e if it exits with an error.

  • parameter after_init

    is called after the server starts listening. since 0.13 .

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 0.14
diff --git a/tiny_httpd/Tiny_httpd_server/module-type-IO_BACKEND/index.html b/tiny_httpd/Tiny_httpd_server/module-type-IO_BACKEND/index.html deleted file mode 100644 index a93bf59c..00000000 --- a/tiny_httpd/Tiny_httpd_server/module-type-IO_BACKEND/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -IO_BACKEND (tiny_httpd.Tiny_httpd_server.IO_BACKEND)

Module type Tiny_httpd_server.IO_BACKEND

A backend that provides IO operations, network operations, etc.

This is used to decouple tiny_httpd from the scheduler/IO library used to actually open a TCP server and talk to clients. The classic way is based on Unix and blocking IOs, but it's also possible to use an OCaml 5 library using effects and non blocking IOs.

val init_addr : unit -> string

Initial TCP address

val init_port : unit -> int

Initial port

val get_time_s : unit -> float

Obtain the current timestamp in seconds.

val tcp_server : unit -> Tiny_httpd_io.TCP_server.builder

TCP server builder, to create servers that can listen on a port and handle clients.

diff --git a/tiny_httpd/Tiny_httpd_server/module-type-SERVER_SENT_GENERATOR/index.html b/tiny_httpd/Tiny_httpd_server/module-type-SERVER_SENT_GENERATOR/index.html deleted file mode 100644 index 41f4e20b..00000000 --- a/tiny_httpd/Tiny_httpd_server/module-type-SERVER_SENT_GENERATOR/index.html +++ /dev/null @@ -1,8 +0,0 @@ - -SERVER_SENT_GENERATOR (tiny_httpd.Tiny_httpd_server.SERVER_SENT_GENERATOR)

Module type Tiny_httpd_server.SERVER_SENT_GENERATOR

A server-side function to generate of Server-sent events.

See the w3c page and this blog post.

  • since 0.9
val set_headers : Headers.t -> unit

Set headers of the response. This is not mandatory but if used at all, it must be called before any call to send_event (once events are sent the response is already sent too).

val send_event : - ?event:string -> - ?id:string -> - ?retry:string -> - data:string -> - unit -> - unit

Send an event from the server. If data is a multiline string, it will be sent on separate "data:" lines.

val close : unit -> unit

Close connection.

  • since 0.11
diff --git a/tiny_httpd/Tiny_httpd_server/module-type-UPGRADE_HANDLER/index.html b/tiny_httpd/Tiny_httpd_server/module-type-UPGRADE_HANDLER/index.html deleted file mode 100644 index 142a1e8f..00000000 --- a/tiny_httpd/Tiny_httpd_server/module-type-UPGRADE_HANDLER/index.html +++ /dev/null @@ -1,7 +0,0 @@ - -UPGRADE_HANDLER (tiny_httpd.Tiny_httpd_server.UPGRADE_HANDLER)

Module type Tiny_httpd_server.UPGRADE_HANDLER

Handler that upgrades to another protocol.

  • since NEXT_RELEASE
type handshake_state

Some specific state returned after handshake

val name : string

Name in the "upgrade" header

val handshake : unit Request.t -> (Headers.t * handshake_state, string) result

Perform the handshake and upgrade the connection. The returned code is 101 alongside these headers. In case the handshake fails, this only returns Error log_msg. The connection is closed without further ado.

val handle_connection : - Unix.sockaddr -> - handshake_state -> - Tiny_httpd_io.Input.t -> - Tiny_httpd_io.Output.t -> - unit

Take control of the connection and take it from ther.e

diff --git a/tiny_httpd/Tiny_httpd_stream/index.html b/tiny_httpd/Tiny_httpd_stream/index.html deleted file mode 100644 index 4fbc2908..00000000 --- a/tiny_httpd/Tiny_httpd_stream/index.html +++ /dev/null @@ -1,33 +0,0 @@ - -Tiny_httpd_stream (tiny_httpd.Tiny_httpd_stream)

Module Tiny_httpd_stream

Byte streams.

Streams are used to represent a series of bytes that can arrive progressively. For example, an uploaded file will be sent as a series of chunks.

These used to live in Tiny_httpd but are now in their own module.

  • since 0.12
type hidden

Type used to make t unbuildable via a record literal. Use make instead.

type t = {
  1. mutable bs : bytes;
    (*

    The bytes

    *)
  2. mutable off : int;
    (*

    Beginning of valid slice in bs

    *)
  3. mutable len : int;
    (*

    Length of valid slice in bs. If len = 0 after a call to fill, then the stream is finished.

    *)
  4. fill_buf : unit -> unit;
    (*

    See the current slice of the internal buffer as bytes, i, len, where the slice is bytes[i] .. [bytes[i+len-1]]. Can block to refill the buffer if there is currently no content. If len=0 then there is no more data.

    *)
  5. consume : int -> unit;
    (*

    Consume n bytes from the buffer. This should only be called with n <= len.

    *)
  6. close : unit -> unit;
    (*

    Close the stream.

    *)
  7. _rest : hidden;
    (*

    Use make to build a stream.

    *)
}

A buffered stream, with a view into the current buffer (or refill if empty), and a function to consume n bytes.

The point of this type is that it gives the caller access to its internal buffer (bs, with the slice off,len). This is convenient for things like line reading where one needs to peek ahead.

Some core invariant for this type of stream are:

  • off,len delimits a valid slice in bs (indices: off, off+1, … off+len-1)
  • if fill_buf() was just called, then either len=0 which indicates the end of stream; or len>0 and the slice contains some data.

To actually move forward in the stream, you can call consume n to consume n bytes (where n <= len). If len gets to 0, calling fill_buf() is required, so it can try to obtain a new slice.

To emulate a classic OCaml reader with a read: bytes -> int -> int -> int function, the simplest is:

let read (self:t) buf offset max_len : int =
-  self.fill_buf();
-  let len = min max_len self.len in
-  if len > 0 then (
-    Bytes.blit self.bs self.off buf offset len;
-    self.consume len;
-  );
-  len
val close : t -> unit

Close stream

val empty : t

Stream with 0 bytes inside

val of_input : ?buf_size:int -> Tiny_httpd_io.Input.t -> t

Make a buffered stream from the given channel.

  • since 0.14
val of_chan : ?buf_size:int -> in_channel -> t

Make a buffered stream from the given channel.

val of_chan_close_noerr : ?buf_size:int -> in_channel -> t

Same as of_chan but the close method will never fail.

val of_fd : ?buf_size:int -> closed:bool ref -> Unix.file_descr -> t

Make a buffered stream from the given file descriptor.

val of_fd_close_noerr : - ?buf_size:int -> - closed:bool ref -> - Unix.file_descr -> - t

Same as of_fd but the close method will never fail.

val of_bytes : ?i:int -> ?len:int -> bytes -> t

A stream that just returns the slice of bytes starting from i and of length len.

val of_string : string -> t
val iter : (bytes -> int -> int -> unit) -> t -> unit

Iterate on the chunks of the stream

  • since 0.3
val to_chan : out_channel -> t -> unit

Write the stream to the channel.

  • since 0.3
val to_chan' : Tiny_httpd_io.Output.t -> t -> unit

Write to the IO channel.

  • since 0.14
val to_writer : t -> Tiny_httpd_io.Writer.t

Turn this stream into a writer.

  • since 0.14
val make : - ?bs:bytes -> - ?close:(t -> unit) -> - consume:(t -> int -> unit) -> - fill:(t -> unit) -> - unit -> - t

make ~fill () creates a byte stream.

  • parameter fill

    is used to refill the buffer, and is called initially.

  • parameter close

    optional closing.

  • parameter init_size

    size of the buffer.

val with_file : ?buf_size:int -> string -> (t -> 'a) -> 'a

Open a file with given name, and obtain an input stream on its content. When the function returns, the stream (and file) are closed.

val read_line : ?buf:Tiny_httpd_buf.t -> t -> string

Read a line from the stream.

  • parameter buf

    a buffer to (re)use. Its content will be cleared.

val read_all : ?buf:Tiny_httpd_buf.t -> t -> string

Read the whole stream into a string.

  • parameter buf

    a buffer to (re)use. Its content will be cleared.

val limit_size_to : - close_rec:bool -> - max_size:int -> - too_big:(int -> unit) -> - t -> - t
val read_chunked : ?buf:Tiny_httpd_buf.t -> fail:(string -> exn) -> t -> t

Convert a stream into a stream of byte chunks using the chunked encoding. The size of chunks is not specified.

  • parameter buf

    buffer used for intermediate storage.

  • parameter fail

    used to build an exception if reading fails.

val read_exactly : - close_rec:bool -> - size:int -> - too_short:(int -> unit) -> - t -> - t

read_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.

  • parameter close_rec

    if true, closing the resulting stream also closes bs

  • parameter too_short

    is called if bs closes with still n bytes remaining

val output_chunked : ?buf:Tiny_httpd_buf.t -> out_channel -> t -> unit

Write the stream into the channel, using the chunked encoding.

  • parameter 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 0.14
diff --git a/tiny_httpd/Tiny_httpd_unix/Dir/Embedded_fs/index.html b/tiny_httpd/Tiny_httpd_unix/Dir/Embedded_fs/index.html new file mode 100644 index 00000000..ef8f7b5b --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix/Dir/Embedded_fs/index.html @@ -0,0 +1,2 @@ + +Embedded_fs (tiny_httpd.Tiny_httpd_unix.Dir.Embedded_fs)

Module Dir.Embedded_fs

An embedded file system, as a list of files with (relative) paths. This is useful in combination with the "tiny-httpd-mkfs" tool, which embeds the files it's given into a OCaml module.

  • since 0.12
type t

The pseudo-filesystem

val create : ?mtime:float -> unit -> t
val add_file : ?mtime:float -> t -> path:string -> string -> unit

Add file to the virtual file system.

  • raises Invalid_argument

    if the path contains '..' or if it tries to make a directory out of an existing path that is a file.

val to_vfs : t -> (module VFS)
diff --git a/tiny_httpd/Tiny_httpd_unix/Dir/index.html b/tiny_httpd/Tiny_httpd_unix/Dir/index.html new file mode 100644 index 00000000..1734068f --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix/Dir/index.html @@ -0,0 +1,25 @@ + +Dir (tiny_httpd.Tiny_httpd_unix.Dir)

Module Tiny_httpd_unix.Dir

Serving static content from directories

This module provides the same functionality as the "http_of_dir" tool. It exposes a directory (and its subdirectories), with the optional ability to delete or upload files.

  • since 0.11
type dir_behavior =
  1. | Index
    (*

    Redirect to index.html if present, else fails.

    *)
  2. | Lists
    (*

    Lists content of directory. Be careful of security implications.

    *)
  3. | Index_or_lists
    (*

    Redirect to index.html if present and lists content otherwise. This is useful for tilde ("~") directories and other per-user behavior, but be mindful of security implications

    *)
  4. | Forbidden
    (*

    Forbid access to directory. This is suited for serving assets, for example.

    *)

behavior of static directory.

This controls what happens when the user requests the path to a directory rather than a file.

type hidden

Type used to prevent users from building a config directly. Use default_config or config instead.

type config = {
  1. mutable download : bool;
    (*

    Is downloading files allowed?

    *)
  2. mutable dir_behavior : dir_behavior;
    (*

    Behavior when serving a directory and not a file

    *)
  3. mutable delete : bool;
    (*

    Is deleting a file allowed? (with method DELETE)

    *)
  4. mutable upload : bool;
    (*

    Is uploading a file allowed? (with method PUT)

    *)
  5. mutable max_upload_size : int;
    (*

    If upload is true, this is the maximum size in bytes for uploaded files.

    *)
  6. _rest : hidden;
    (*

    Just ignore this field.

    *)
}

configuration for static file handlers. This might get more fields over time.

val default_config : unit -> config

default configuration: + { download=true + ; dir_behavior=Forbidden + ; delete=false + ; upload=false + ; max_upload_size = 10 * 1024 * 1024 + }

val config : + ?download:bool -> + ?dir_behavior:dir_behavior -> + ?delete:bool -> + ?upload:bool -> + ?max_upload_size:int -> + unit -> + config

Build a config from default_config.

  • since 0.12
val add_dir_path : + config:config -> + dir:string -> + prefix:string -> + Tiny_httpd_core.Server.t -> + unit

add_dirpath ~config ~dir ~prefix server adds route handle to the server to serve static files in dir when url starts with prefix, using the given configuration config.

module type VFS = sig ... end

Virtual file system.

val vfs_of_dir : string -> (module VFS)

vfs_of_dir dir makes a virtual file system that reads from the disk.

  • since 0.12
val add_vfs : + config:config -> + vfs:(module VFS) -> + prefix:string -> + Tiny_httpd_core.Server.t -> + unit

Similar to add_dir_path but using a virtual file system instead.

  • since 0.12
module Embedded_fs : sig ... end

An embedded file system, as a list of files with (relative) paths. This is useful in combination with the "tiny-httpd-mkfs" tool, which embeds the files it's given into a OCaml module.

diff --git a/tiny_httpd/Tiny_httpd_unix/Dir/module-type-VFS/index.html b/tiny_httpd/Tiny_httpd_unix/Dir/module-type-VFS/index.html new file mode 100644 index 00000000..c914ee7b --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix/Dir/module-type-VFS/index.html @@ -0,0 +1,2 @@ + +VFS (tiny_httpd.Tiny_httpd_unix.Dir.VFS)

Module type Dir.VFS

Virtual file system.

This is used to emulate a file system from pure OCaml functions and data, e.g. for resources bundled inside the web server.

  • since 0.12
val descr : string

Description of the VFS

val is_directory : string -> bool
val contains : string -> bool

file_exists vfs path returns true if path points to a file or directory inside vfs.

val list_dir : string -> string array

List directory. This only returns basenames, the files need to be put in the directory path using Filename.concat.

val delete : string -> unit

Delete path

val create : string -> (bytes -> int -> int -> unit) * (unit -> unit)

Create a file and obtain a pair write, close

val read_file_content : string -> Tiny_httpd_core.IO.Input.t

Read content of a file

val file_size : string -> int option

File size, e.g. using "stat"

val file_mtime : string -> float option

File modification time, e.g. using "stat"

diff --git a/tiny_httpd/Tiny_httpd_unix/Sem/index.html b/tiny_httpd/Tiny_httpd_unix/Sem/index.html new file mode 100644 index 00000000..b65aa66e --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix/Sem/index.html @@ -0,0 +1,2 @@ + +Sem (tiny_httpd.Tiny_httpd_unix.Sem)

Module Tiny_httpd_unix.Sem

semaphore, for limiting concurrency.

type t = {
  1. mutable n : int;
  2. max : int;
  3. mutex : Stdlib.Mutex.t;
  4. cond : Stdlib.Condition.t;
}
val create : int -> t
val acquire : int -> t -> unit
val release : int -> t -> unit
val num_acquired : t -> int
diff --git a/tiny_httpd/Tiny_httpd_unix/Unix_tcp_server_/index.html b/tiny_httpd/Tiny_httpd_unix/Unix_tcp_server_/index.html new file mode 100644 index 00000000..30d8028b --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix/Unix_tcp_server_/index.html @@ -0,0 +1,2 @@ + +Unix_tcp_server_ (tiny_httpd.Tiny_httpd_unix.Unix_tcp_server_)

Module Tiny_httpd_unix.Unix_tcp_server_

val get_addr_ : Unix.file_descr -> Unix.inet_addr * int
type t = {
  1. addr : string;
  2. port : int;
  3. buf_pool : Tiny_httpd_core.Buf.t Tiny_httpd_core.Pool.t;
  4. slice_pool : Tiny_httpd_core.IO.Slice.t Tiny_httpd_core.Pool.t;
  5. max_connections : int;
  6. sem_max_connections : Sem.t;
    (*

    semaphore to restrict the number of active concurrent connections

    *)
  7. mutable sock : Unix.file_descr option;
    (*

    Socket

    *)
  8. new_thread : (unit -> unit) -> unit;
  9. timeout : float;
  10. masksigpipe : bool;
  11. mutable running : bool;
}
val shutdown_silent_ : Unix.file_descr -> unit
val close_silent_ : Unix.file_descr -> unit
diff --git a/tiny_httpd/Tiny_httpd_unix/index.html b/tiny_httpd/Tiny_httpd_unix/index.html new file mode 100644 index 00000000..3e19748c --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_unix (tiny_httpd.Tiny_httpd_unix)

Module Tiny_httpd_unix

module Dir : sig ... end

Serving static content from directories

module Sem : sig ... end

semaphore, for limiting concurrency.

module Unix_tcp_server_ : sig ... end
diff --git a/tiny_httpd/Tiny_httpd_unix__/index.html b/tiny_httpd/Tiny_httpd_unix__/index.html new file mode 100644 index 00000000..e229fd6c --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix__/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_unix__ (tiny_httpd.Tiny_httpd_unix__)

Module Tiny_httpd_unix__

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_unix__Dir/index.html b/tiny_httpd/Tiny_httpd_unix__Dir/index.html new file mode 100644 index 00000000..b1975433 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix__Dir/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_unix__Dir (tiny_httpd.Tiny_httpd_unix__Dir)

Module Tiny_httpd_unix__Dir

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_unix__Sem/index.html b/tiny_httpd/Tiny_httpd_unix__Sem/index.html new file mode 100644 index 00000000..6da54943 --- /dev/null +++ b/tiny_httpd/Tiny_httpd_unix__Sem/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_unix__Sem (tiny_httpd.Tiny_httpd_unix__Sem)

Module Tiny_httpd_unix__Sem

This module is hidden.

diff --git a/tiny_httpd/Tiny_httpd_util/index.html b/tiny_httpd/Tiny_httpd_util/index.html deleted file mode 100644 index 20d80fad..00000000 --- a/tiny_httpd/Tiny_httpd_util/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Tiny_httpd_util (tiny_httpd.Tiny_httpd_util)

Module Tiny_httpd_util

Some utils for writing web servers

  • since 0.2
val percent_encode : ?skip:(char -> bool) -> string -> string

Encode the string into a valid path following https://tools.ietf.org/html/rfc3986#section-2.1

  • parameter skip

    if provided, allows to preserve some characters, e.g. '/' in a path.

val percent_decode : string -> string option

Inverse operation of percent_encode. Can fail since some strings are not valid percent encodings.

val split_query : string -> string * string

Split a path between the path and the query

  • since 0.5
val split_on_slash : string -> string list

Split a string on '/', remove the trailing '/' if any.

  • since 0.6
val get_non_query_path : string -> string

get the part of the path that is not the query parameters.

  • since 0.5
val get_query : string -> string

Obtain the query part of a path.

  • since 0.4
val parse_query : string -> ((string * string) list, string) result

Parse a query as a list of '&' or ';' separated key=value pairs. The order might not be preserved.

  • since 0.3
val show_sockaddr : Unix.sockaddr -> string

Simple printer for socket addresses.

  • since NEXT_RELEASE
diff --git a/tiny_httpd/Tiny_httpd_ws/index.html b/tiny_httpd/Tiny_httpd_ws/index.html index 83cfcb7f..b19fefa3 100644 --- a/tiny_httpd/Tiny_httpd_ws/index.html +++ b/tiny_httpd/Tiny_httpd_ws/index.html @@ -1,9 +1,17 @@ -Tiny_httpd_ws (tiny_httpd.Tiny_httpd_ws)

Module Tiny_httpd_ws

Websockets for Tiny_httpd.

This sub-library (tiny_httpd.ws) exports a small implementation for a websocket server. It has no additional dependencies.

module IO = Tiny_httpd_io
type handler = Unix.sockaddr -> IO.Input.t -> IO.Output.t -> unit

Websocket handler

Upgrade a byte stream to the websocket framing protocol.

val add_route_handler : - ?accept:(unit Tiny_httpd_server.Request.t -> (unit, int * string) result) -> +Tiny_httpd_ws (tiny_httpd.Tiny_httpd_ws)

Module Tiny_httpd_ws

Websockets for Tiny_httpd.

This sub-library (tiny_httpd.ws) exports a small implementation for a websocket server. It has no additional dependencies.

Websocket handler

Upgrade a byte stream to the websocket framing protocol.

Add a route handler for a websocket endpoint.

  • parameter accept_ws_protocol

    decides whether this endpoint accepts the websocket protocol sent by the client. Default accepts everything.

diff --git a/tiny_httpd/index.html b/tiny_httpd/index.html index f2c4ca1f..51e2c6cf 100644 --- a/tiny_httpd/index.html +++ b/tiny_httpd/index.html @@ -1,2 +1,2 @@ -index (tiny_httpd.index)

Package tiny_httpd

Package info

changes-files
readme-files
+index (tiny_httpd.index)

Package tiny_httpd

Package info

changes-files
readme-files
diff --git a/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html b/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html index f6d493d2..cfba0719 100644 --- a/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html +++ b/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html @@ -3,4 +3,8 @@ ?compress_above:int -> ?buf_size:int -> unit -> - Tiny_httpd_server.Middleware.t

Middleware responsible for deflate compression/decompression.

  • parameter compress_above

    threshold, in bytes, above which a response body that has a known content-length is compressed. Stream bodies are always compressed.

  • parameter buf_size

    size of the underlying buffer for compression/decompression

  • since 0.11
val setup : ?compress_above:int -> ?buf_size:int -> Tiny_httpd_server.t -> unit

Install middleware for tiny_httpd to be able to encode/decode compressed streams

  • parameter compress_above

    threshold above with string responses are compressed

  • parameter buf_size

    size of the underlying buffer for compression/decompression

+ Tiny_httpd_core.Server.Middleware.t

Middleware responsible for deflate compression/decompression.

  • parameter compress_above

    threshold, in bytes, above which a response body that has a known content-length is compressed. Stream bodies are always compressed.

  • parameter buf_size

    size of the underlying buffer for compression/decompression

  • since 0.11
val setup : + ?compress_above:int -> + ?buf_size:int -> + Tiny_httpd_core.Server.t -> + unit

Install middleware for tiny_httpd to be able to encode/decode compressed streams

  • parameter compress_above

    threshold above with string responses are compressed

  • parameter buf_size

    size of the underlying buffer for compression/decompression