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 @@ + +
Hmap.KeyKeys.
val create : unit -> 'a keycreate () is a new key.
Exisential keys allows to compare keys. This can be useful for functions like filter.
Make.KeyKeys.
type 'a info = 'a Key_info.tThe type for key information.
Exisential keys allow to compare keys. This can be useful for functions like filter.
Make.Key_infoHmap.MakeFunctor for heterogeneous maps whose keys hold information of type Key_info.t
module Key : sig ... endKeys.
val empty : tempty is the empty map.
val is_empty : t -> boolis_empty m is true iff m is empty.
fold f m acc folds over the bindings of m with f, starting with acc
exists p m is true iff there exists a bindings of m that satisfies p.
val cardinal : t -> intcardinal m is the number of bindings in m.
HmapHeterogeneous value maps.
v0.8.1 - homepage
module Key : sig ... endKeys.
val empty : tempty is the empty map.
val is_empty : t -> boolis_empty m is true iff m is empty.
fold f m acc folds over the bindings of m with f, starting with acc
exists p m is true iff there exists a bindings of m that satisfies p.
val cardinal : t -> intcardinal m is the number of bindings in m.
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 ... endThe type for key information.
Hmap.KEY_INFOThe type for key information.
S.KeyKeys.
Exisential keys allow to compare keys. This can be useful for functions like filter.
Hmap.SOutput signature of the functor Make
module Key : sig ... endKeys.
val empty : tempty is the empty map.
val is_empty : t -> boolis_empty m is true iff m is empty.
fold f m acc folds over the bindings of m with f, starting with acc
exists p m is true iff there exists a bindings of m that satisfies p.
val cardinal : t -> intcardinal m is the number of bindings in m.
Hmap Heterogeneous value maps.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
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
In.emptyRead into the slice. Returns 0 only if the stream is closed.
In.of_bytesinherit tinherit Iostream__.Seekable.tIn.of_in_channelinherit tinherit Iostream__.Seekable.tIn.of_stringinherit tinherit Iostream__.Seekable.tIn.open_fileinherit tinherit Iostream__.Seekable.tIn.tAn 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.
Read into the slice. Returns 0 only if the stream is closed.
In.t_seekableAn input stream that is also seekable.
inherit tinherit Iostream__.Seekable.tIostream.InInput stream.
class type t = object ... endAn input stream, i.e an incoming stream of bytes.
class type t_seekable = object ... endAn input stream that is also seekable.
val create :
+ ?close:(unit -> unit) ->
+ input:(bytes -> int -> int -> int) ->
+ unit ->
+ tval empty : tEmpty input, contains 0 bytes.
class of_in_channel : ?close_noerr:bool -> in_channel -> t_seekableval of_in_channel : ?close_noerr:bool -> in_channel -> t_seekableWrap a standard input channel.
class open_file : ?close_noerr:bool -> ?mode:int -> ?flags:open_flag list -> string ->
+ t_seekableval open_file :
+ ?close_noerr:bool ->
+ ?mode:int ->
+ ?flags:open_flag list ->
+ string ->
+ t_seekableval with_open_file :
+ ?close_noerr:bool ->
+ ?mode:int ->
+ ?flags:open_flag list ->
+ string ->
+ (t_seekable -> 'a) ->
+ 'aclass of_string : ?off:int -> ?len:int -> string -> t_seekableval of_string : ?off:int -> ?len:int -> string -> t_seekableAn input channel reading from the string.
class of_bytes : ?off:int -> ?len:int -> bytes -> t_seekableval of_bytes : ?off:int -> ?len:int -> bytes -> t_seekableAn input channel reading from the bytes buffer. See of_string for more details.
val input : t -> bytes -> int -> int -> intRead bytes into the given buffer. This returns 0 only if the stream has reached its end.
val input_all_into_buffer : t -> Stdlib.Buffer.t -> unitRead the whole content into the given buffer.
val input_all : ?buf:bytes -> t -> stringinput_all ic reads the whole content of ic into a string.
val really_input : t -> bytes -> int -> int -> unitSame as input, but reads exactly the demanded amount of bytes.
val really_input_string : t -> int -> stringreally_input_string ic n reads exactly n bytes of ic and returns them as a string.
val close : t -> unitClose the input stream. This is idempotent.
In_buf.bufferizedinherit Iostream__.In.tic#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.
In_buf.of_bytesinherit Iostream__.In.tic#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.
In_buf.of_in_channelinherit Iostream__.In.tic#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.
In_buf.of_stringinherit Iostream__.In.tic#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.
In_buf.open_fileinherit Iostream__.In.tic#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.
In_buf.t_from_refillA mixin to implement a buffered input by only providing a refill method. Add a close method and it's good to go.
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.
In_buf.tThe implementation of buffered input streams.
inherit Iostream__.In.tic#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.
Iostream.In_bufBuffered input stream.
class type t = object ... endThe implementation of buffered input streams.
class virtual t_from_refill : ?bytes:bytes -> unit -> object ... endA 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 ->
+ tCreate a new buffered input stream.
val of_bytes : ?off:int -> ?len:int -> bytes -> tval of_string : ?off:int -> ?len:int -> string -> tclass bufferized : ?bytes:bytes -> In.t -> tRead from the given buffer.
class of_in_channel : ?bytes:bytes -> in_channel -> tval of_in_channel : ?bytes:bytes -> in_channel -> tWrap a standard input channel.
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 -> intRead into the given slice of bytes.
val consume : t -> int -> unitconsume 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 -> unitClose the input stream.
val input_all_into_buffer : t -> Stdlib.Buffer.t -> unitRead the whole content into the given buffer.
val input_all : ?buf:bytes -> t -> stringinput_all ic reads the whole content of ic into a string.
val skip : t -> int -> unitskip ic n reads and dicards the next n bytes in ic.
val input_line : ?buffer:Stdlib.Buffer.t -> t -> string optionRead a line from the input. Return None if the stream is empty.
val input_lines : ?buffer:Stdlib.Buffer.t -> t -> string listRead all lines from the input.
val to_iter : t -> (char -> unit) -> unitval to_seq : t -> char Stdlib.Seq.tval of_seq : ?bytes:bytes -> char Stdlib.Seq.t -> tOut.dummyOut.map_charOut.of_bufferOut.of_out_channelinherit tinherit Iostream__.Seekable.tOut.tAn 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.
Out.t_seekableinherit tinherit Iostream__.Seekable.tIostream.OutOutput stream.
class type t = object ... endAn 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 ... endval dummy : tDummy output, drops everything written to it.
class of_out_channel : ?close_noerr:bool -> out_channel -> t_seekableval of_out_channel : ?close_noerr:bool -> out_channel -> t_seekableWrap an out channel.
class of_buffer : Stdlib.Buffer.t -> tval of_buffer : Stdlib.Buffer.t -> tof_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_seekableopen_file file creates an out stream writing into the given file.
val with_open_file :
+ ?close_noerr:bool ->
+ ?mode:int ->
+ ?flags:open_flag list ->
+ string ->
+ (t_seekable -> 'a) ->
+ 'aval output : t -> bytes -> int -> int -> unitWrite the slice of bytes.
val close : t -> unitClose the stream. Idempotent.
val output_string : t -> string -> unitOutput the whole string.
val output_int : t -> int -> unitOutput an integer in decimal notation.
tee ocs is an output that accepts bytes and writes them to every output in ocs. When closed, it closes all elements of oc.
Out_buf.bufferizedinherit Iostream__.Out.tOut_buf.dummyinherit Iostream__.Out.tOut_buf.of_bufferinherit Iostream__.Out.tOut_buf.of_out_channelinherit tinherit Iostream__.Seekable.tOut_buf.open_fileinherit tinherit Iostream__.Seekable.tOut_buf.t_from_outputMake a bufferized output from a non bufferized output+close.
inherit tEmit these private bytes, unbufferized
Out_buf.tAn 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.tOut_buf.t_seekableinherit tinherit Iostream__.Seekable.tIostream.Out_bufBuffered output stream.
class type t = object ... endAn 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 ... endval create :
+ ?flush:(unit -> unit) ->
+ ?close:(unit -> unit) ->
+ output_char:(char -> unit) ->
+ output:(bytes -> int -> int -> unit) ->
+ unit ->
+ tCreate a new output stream from raw components.
val dummy : tDummy output, drops everything written to it.
class virtual t_from_output : ?bytes:bytes -> unit -> object ... endMake a bufferized output from a non bufferized output+close.
class bufferized : ?bytes:bytes -> Out.t -> tclass of_out_channel : ?close_noerr:bool -> out_channel -> t_seekableval of_out_channel : ?close_noerr:bool -> out_channel -> t_seekableWrap an out channel.
class of_buffer : Stdlib.Buffer.t -> tval of_buffer : Stdlib.Buffer.t -> tof_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_seekableval open_file :
+ ?close_noerr:bool ->
+ ?mode:int ->
+ ?flags:open_flag list ->
+ string ->
+ t_seekableopen_file file creates an out stream writing into the given file.
val with_open_file :
+ ?close_noerr:bool ->
+ ?mode:int ->
+ ?flags:open_flag list ->
+ string ->
+ (t_seekable -> 'a) ->
+ 'aval output_char : t -> char -> unitOutput a single char
val output : t -> bytes -> int -> int -> unitWrite the slice of bytes.
val close : t -> unitClose the stream. Idempotent.
val flush : t -> unitEnsure 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 -> unitOutput the whole string.
val output_line : t -> string -> unitOutput the whole string followed by '\n'.
val output_lines : t -> string Stdlib.Seq.t -> unitOutput a series of lines, each terminated by '\n'.
val output_int : t -> int -> unitOutput an integer in decimal notation.
tee ocs is an output that accepts bytes and writes them to every output in ocs. When closed, it closes all elements of oc.
Seekable.tIostream.SeekableAn object we can seek in.
Files can be seeked in, i.e the read/write head can move around.
Iostream.SliceByte slice or buffer.
type t = {bytes : bytes;Bytes
*)mutable off : int;Offset in bytes
*)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 : tval create : int -> tval of_bytes : bytes -> tval bytes : t -> bytesval off : t -> intval len : t -> intval consume : t -> int -> unitConsume the first n bytes from the slice, making it n bytes shorter. This modifies the slice in place.
val find_index_exn : t -> char -> intfind index of c in slice, or raise Not_found
IostreamI/O streams.
This module defines generic I/O streams. They can be user-defined and can be composed from other streams.
module In : sig ... endInput stream.
module In_buf : sig ... endBuffered input stream.
module Out : sig ... endOutput stream.
module Out_buf : sig ... endBuffered output stream.
module Slice : sig ... endByte slice or buffer.
module Seekable : sig ... endAn object we can seek in.
Iostream__This module is hidden.
Iostream__InThis module is hidden.
Iostream__In_bufThis module is hidden.
Iostream__OutThis module is hidden.
Iostream__Out_bufThis module is hidden.
Iostream__SeekableThis module is hidden.
Iostream__SliceThis module is hidden.
Iostream_unix.Inval of_unix_fd : ?close_noerr:bool -> Unix.file_descr -> Iostream.In.t_seekableCreate an in stream from a raw Unix file descriptor. The file descriptor must be opened for reading.
Iostream_unix.Outval of_unix_fd : Unix.file_descr -> Iostream.Out.t_seekableOutput stream directly writing into the given Unix file descriptor.
Iostream_unixIostream I/O streams.Iostream_unix These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.
module Buf = Tiny_httpd_bufmodule Byte_stream = Tiny_httpd_streammodule IO = Tiny_httpd_iomodule Log = Tiny_httpd_logtype buf = Tiny_httpd_buf.ttype byte_stream = Tiny_httpd_stream.tmodule Meth = Tiny_httpd_server.MethHeaders are metadata associated with a request or response.
module Headers = Tiny_httpd_server.HeadersRequests 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.Requestmodule Response_code = Tiny_httpd_server.Response_codeResponses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t
module Response = Tiny_httpd_server.ResponseBasic 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.
module Route = Tiny_httpd_server.RouteA middleware can be inserted in a handler to modify or observe its behavior.
module Middleware = Tiny_httpd_server.Middlewaretype t = Tiny_httpd_server.tA HTTP server. See create for more details.
val create :
+ path="/echo"; body="howdy y'all"}These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.
module Buf = Tiny_httpd_core.Bufmodule IO = Tiny_httpd_core.IOmodule Log = Tiny_httpd_core.Logmodule Util = Tiny_httpd_core.Utilmodule Pool = Tiny_httpd_core.Poolmodule Dir = Tiny_httpd_unix.Dirmodule type VFS = Tiny_httpd_unix.Dir.VFSmodule Html = Tiny_httpd_htmlAlias to Tiny_httpd_html
module Request = Tiny_httpd_core.Requestmodule Response = Tiny_httpd_core.Responsemodule Response_code = Tiny_httpd_core.Response_codemodule Route = Tiny_httpd_core.Routemodule Headers = Tiny_httpd_core.Headersmodule Meth = Tiny_httpd_core.Methmodule Server = Tiny_httpd_core.ServerA middleware can be inserted in a handler to modify or observe its behavior.
module Middleware = Server.Middlewaretype t = Tiny_httpd_core.Server.tA HTTP server. See create for more details.
module type IO_BACKEND = Server.IO_BACKENDA 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 ->
+ tCreate 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.
val addr : t -> stringAddress on which the server listens.
val is_ipv6 : t -> boolis_ipv6 server returns true iff the address of the server is an IPv6 address.
val port : t -> intPort 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 -> intNumber 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) ->
+ unitAdd 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) ->
+ unitAdd 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 ->
+ unitAdd a middleware to every request/response pair.
val set_top_handler :
+ t ->
+ (Tiny_httpd_core.IO.Input.t Tiny_httpd_core.Request.t ->
+ Tiny_httpd_core.Response.t) ->
+ unitSetup 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 ->
+ unitadd_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.
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 ->
+ unitSimilar 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.
EXPERIMENTAL: this API is not stable yet.
module type SERVER_SENT_GENERATOR = Server.SERVER_SENT_GENERATORA 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).
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 ->
+ unitAdd 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).
These handlers upgrade the connection to another protocol.
module type UPGRADE_HANDLER = Server.UPGRADE_HANDLERHandler that upgrades to another protocol.
type upgrade_handler = (module UPGRADE_HANDLER)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 ->
+ unitval running : t -> boolIs the server running?
val stop : t -> unitAsk the server to stop. This might not have an immediate effect as run might currently be waiting on IO.
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.
val run_exn : ?after_init:(unit -> unit) -> t -> unitrun_exn s is like run s but re-raises an exception if the server exits with an error.
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 ->
- tCreate 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.
module type IO_BACKEND = Tiny_httpd_server.IO_BACKENDA 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 ->
- tCreate 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.
val addr : t -> stringAddress on which the server listens.
val is_ipv6 : t -> boolis_ipv6 server returns true iff the address of the server is an IPv6 address.
val port : t -> intPort 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 -> intNumber of currently active connections.
val add_decode_request_cb :
- t ->
- (unit Request.t -> (unit Request.t * (byte_stream -> byte_stream)) option) ->
- unitAdd 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) ->
- unitAdd 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 ->
- unitAdd a middleware to every request/response pair.
val set_top_handler : t -> (byte_stream Request.t -> Response.t) -> unitSetup 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 ->
- unitadd_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.
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 ->
- unitSimilar 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.
EXPERIMENTAL: this API is not stable yet.
module type SERVER_SENT_GENERATOR = Tiny_httpd_server.SERVER_SENT_GENERATORA 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).
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 ->
- unitAdd 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).
These handlers upgrade the connection to another protocol.
module type UPGRADE_HANDLER = Tiny_httpd_server.UPGRADE_HANDLERHandler that upgrades to another protocol.
type upgrade_handler = (module UPGRADE_HANDLER)val add_upgrade_handler :
- ?accept:(unit Request.t -> (unit, Response_code.t * string) result) ->
- t ->
- ('a, upgrade_handler) Route.t ->
- 'a ->
- unitval running : t -> boolIs the server running?
val stop : t -> unitAsk the server to stop. This might not have an immediate effect as run might currently be waiting on IO.
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.
val run_exn : ?after_init:(unit -> unit) -> t -> unitrun_exn s is like run s but re-raises an exception if the server exits with an error.
module Util = Tiny_httpd_utilmodule Pool = Tiny_httpd_poolmodule Dir = Tiny_httpd_dirmodule Html = Tiny_httpd_htmlAlias to Tiny_httpd_html