diff --git a/0.12/tiny_httpd/Tiny_httpd/index.html b/0.12/tiny_httpd/Tiny_httpd/index.html index d9825a78..37b489df 100644 --- a/0.12/tiny_httpd/Tiny_httpd/index.html +++ b/0.12/tiny_httpd/Tiny_httpd/index.html @@ -1,5 +1,5 @@ -
Tiny_httpdThis library implements a very simple, basic HTTP/1.1 server using blocking IOs and threads. Basic routing based on Scanf is provided for convenience, so that several handlers can be registered.
It is possible to use a thread pool, see create's argument new_thread.
The echo example (see src/examples/echo.ml) demonstrates some of the features by declaring a few endpoints, including one for uploading files:
module S = Tiny_httpd
+Tiny_httpd (tiny_httpd.Tiny_httpd) Module Tiny_httpd
Tiny Http Server
This library implements a very simple, basic HTTP/1.1 server using blocking IOs and threads. Basic routing based on Scanf is provided for convenience, so that several handlers can be registered.
It is possible to use a thread pool, see create's argument new_thread.
The echo example (see src/examples/echo.ml) demonstrates some of the features by declaring a few endpoints, including one for uploading files:
module S = Tiny_httpd
let () =
let server = S.create () in
@@ -49,10 +49,10 @@ 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_bufGeneric stream of data
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.
module Byte_stream = Tiny_httpd_streamMain Server Type
include module type of struct include Tiny_httpd_server end
type buf = Tiny_httpd_buf.ttype byte_stream = Tiny_httpd_stream.tMethods
module Meth = Tiny_httpd_server.MethHeaders
Headers are metadata associated with a request or response.
module Headers = Tiny_httpd_server.HeadersRequests
Requests are sent by a client, e.g. a web browser or cURL.
module Request = Tiny_httpd_server.RequestResponse Codes
module Response_code = Tiny_httpd_server.Response_codeResponses
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.Responsemodule Route = Tiny_httpd_server.Routemodule Middleware = Tiny_httpd_server.MiddlewareMain Server type
type t = Tiny_httpd_server.tA HTTP server. See create for more details.
val create : ?masksigpipe:bool -> ?max_connections:int -> ?timeout:float ->
+ 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_bufGeneric stream of data
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.
module Byte_stream = Tiny_httpd_streamMain Server Type
type buf = Tiny_httpd_buf.ttype byte_stream = Tiny_httpd_stream.tMethods
module Meth = Tiny_httpd_server.MethHeaders
Headers are metadata associated with a request or response.
module Headers = Tiny_httpd_server.HeadersRequests
Requests are sent by a client, e.g. a web browser or cURL.
module Request = Tiny_httpd_server.RequestResponse Codes
module Response_code = Tiny_httpd_server.Response_codeResponses
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.Responsemodule Route = Tiny_httpd_server.Routemodule Middleware = Tiny_httpd_server.MiddlewareMain Server type
type t = Tiny_httpd_server.tA 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 -> tCreate a new webserver.
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.
val active_connections : t -> intNumber of 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.
Request handlers
val set_top_handler : t -> (string 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.
val add_route_handler : ?accept:(unit Request.t -> (unit, Response_code.t * string) Stdlib.result) ->
+?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> unit -> tCreate a new webserver.
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.
val active_connections : t -> intNumber of 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.
Request handlers
val set_top_handler : t -> (string 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.
val add_route_handler : ?accept:(unit Request.t -> (unit, Response_code.t * string) Stdlib.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) Stdlib.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.
Server-sent events
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
val add_route_server_sent_handler : ?accept:(unit Request.t -> (unit, Response_code.t * string) Stdlib.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).
Run the server
val stop : t -> unitAsk the server to stop. This might not have an immediate effect as run might currently be waiting on IO.
val run : t -> (unit, exn) Stdlib.resultRun 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.
Utils
module Util = Tiny_httpd_utilStatic directory serving
module Dir = Tiny_httpd_dir
\ No newline at end of file
+?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.
Server-sent events
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
val add_route_server_sent_handler : ?accept:(unit Request.t -> (unit, Response_code.t * string) Stdlib.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).
Run the server
val stop : t -> unitAsk the server to stop. This might not have an immediate effect as run might currently be waiting on IO.
val run : t -> (unit, exn) Stdlib.resultRun 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.
Utils
module Util = Tiny_httpd_utilStatic directory serving
module Dir = Tiny_httpd_dirTiny_httpd_serverHTTP server.
This library 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.
type buf = Tiny_httpd_buf.ttype byte_stream = Tiny_httpd_stream.tmodule Meth : sig ... endHeaders are metadata associated with a request or response.
module Headers : sig ... endRequests are sent by a client, e.g. a web browser or cURL.
module Request : sig ... endmodule Response_code : sig ... endResponses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t
module Response : sig ... endmodule Route : sig ... endmodule Middleware : sig ... endA HTTP server. See create for more details.
val create : ?masksigpipe:bool -> ?max_connections:int -> ?timeout:float ->
+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.
type buf = Tiny_httpd_buf.ttype byte_stream = Tiny_httpd_stream.tMethods
module Meth : sig ... endHeaders
Headers are metadata associated with a request or response.
module Headers : sig ... endRequests
Requests are sent by a client, e.g. a web browser or cURL.
module Request : sig ... endResponse Codes
module Response_code : sig ... endResponses
Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t
module Response : sig ... endmodule Route : sig ... endmodule Middleware : sig ... endMain Server type
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 -> tCreate a new webserver.
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.
val active_connections : t -> intNumber of 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.
Request handlers
val set_top_handler : t -> (string 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.
val add_route_handler : ?accept:(unit Request.t -> (unit, Response_code.t * string) Stdlib.result) ->
diff --git a/0.12/tiny_httpd/Tiny_httpd_stream/index.html b/0.12/tiny_httpd/Tiny_httpd_stream/index.html
index 2015e604..d99dddef 100644
--- a/0.12/tiny_httpd/Tiny_httpd_stream/index.html
+++ b/0.12/tiny_httpd/Tiny_httpd_stream/index.html
@@ -1,3 +1,3 @@
-Tiny_httpd_stream (tiny_httpd.Tiny_httpd_stream) Module Tiny_httpd_stream
type t = {mutable bs : bytes;(*The bytes
*) mutable off : int;(*Beginning of valid slice in bs
*) mutable len : int;(*Length of valid slice in bs. If len = 0 after a call to fill, then the stream is finished.
*) 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.
*) consume : int -> unit;(*Consume n bytes from the buffer. This should only be called with n <= len.
*) close : unit -> unit;(*Close the stream.
*) _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. See Byte_stream for more details.
val close : t -> unitval empty : tval of_chan : ?buf_size:int -> Stdlib.in_channel -> tMake a buffered stream from the given channel.
val of_chan_close_noerr : ?buf_size:int -> Stdlib.in_channel -> tSame as of_chan but the close method will never fail.
val of_bytes : ?i:int -> ?len:int -> bytes -> tA stream that just returns the slice of bytes starting from i and of length len.
val of_string : string -> tval iter : (bytes -> int -> int -> unit) -> t -> unitIterate on the chunks of the stream
val to_chan : Stdlib.out_channel -> t -> unitWrite the stream to the channel.
val make : ?bs:bytes -> ?close:(t -> unit) -> consume:(t -> int -> unit) -> fill:(t -> unit) ->
+Tiny_httpd_stream (tiny_httpd.Tiny_httpd_stream) Module Tiny_httpd_stream
Byte streams.
These used to live in Tiny_httpd but are now in their own module.
type t = {mutable bs : bytes;(*The bytes
*) mutable off : int;(*Beginning of valid slice in bs
*) mutable len : int;(*Length of valid slice in bs. If len = 0 after a call to fill, then the stream is finished.
*) 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.
*) consume : int -> unit;(*Consume n bytes from the buffer. This should only be called with n <= len.
*) close : unit -> unit;(*Close the stream.
*) _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. See Byte_stream for more details.
val close : t -> unitClose stream
val empty : tStream with 0 bytes inside
val of_chan : ?buf_size:int -> Stdlib.in_channel -> tMake a buffered stream from the given channel.
val of_chan_close_noerr : ?buf_size:int -> Stdlib.in_channel -> tSame as of_chan but the close method will never fail.
val of_bytes : ?i:int -> ?len:int -> bytes -> tA stream that just returns the slice of bytes starting from i and of length len.
val of_string : string -> tval iter : (bytes -> int -> int -> unit) -> t -> unitIterate on the chunks of the stream
val to_chan : Stdlib.out_channel -> t -> unitWrite the stream to the channel.
val make : ?bs:bytes -> ?close:(t -> unit) -> consume:(t -> int -> unit) -> fill:(t -> unit) ->
unit -> tmake ~fill () creates a byte stream.
val with_file : ?buf_size:int -> string -> (t -> 'a) -> 'aOpen 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 -> stringRead a line from the stream.
val read_all : ?buf:Tiny_httpd_buf.t -> t -> stringRead the whole stream into a string.
val read_chunked : ?buf:Tiny_httpd_buf.t -> fail:(string -> exn) -> t -> tConvert a stream into a stream of byte chunks using the chunked encoding. The size of chunks is not specified.
read_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.
val output_chunked : Stdlib.out_channel -> t -> unitWrite the stream into the channel, using the chunked encoding.
\ No newline at end of file
diff --git a/0.12/tiny_httpd/index.html b/0.12/tiny_httpd/index.html
index dcd58617..41d8ccb5 100644
--- a/0.12/tiny_httpd/index.html
+++ b/0.12/tiny_httpd/index.html
@@ -1,2 +1,2 @@
-index (tiny_httpd.index) tiny_httpd index
Library tiny_httpd
This library exposes the following toplevel modules:
Tiny_httpd Tiny_httpd_buf Simple buffer.Tiny_httpd_dir Serving static content from directoriesTiny_httpd_html HTML combinators.Tiny_httpd_html_ Tiny_httpd_server HTTP server.Tiny_httpd_stream Tiny_httpd_util
\ No newline at end of file
+index (tiny_httpd.index) tiny_httpd index
Library tiny_httpd
This library exposes the following toplevel modules:
Tiny_httpd Tiny_httpd_buf Simple buffer.Tiny_httpd_dir Serving static content from directoriesTiny_httpd_html HTML combinators.Tiny_httpd_html_ Tiny_httpd_server HTTP server.Tiny_httpd_stream Byte streams.Tiny_httpd_util
\ No newline at end of file