diff --git a/dev/tiny_httpd/Tiny_httpd/index.html b/dev/tiny_httpd/Tiny_httpd/index.html index c6a51dbc..403f6782 100644 --- a/dev/tiny_httpd/Tiny_httpd/index.html +++ b/dev/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,7 +49,7 @@ 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
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 :
+ 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 byte streams
module Byte_stream = Tiny_httpd_streamMain Server Type
type buf = Tiny_httpd_buf.ttype byte_stream = Tiny_httpd_stream.tHTTP Methods
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. From the point of view of the server, they're inputs.
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.ResponseRouting
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.
module Route = Tiny_httpd_server.RouteMiddlewares
A middleware can be inserted in a handler to modify or observe its behavior.
module 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 ->
@@ -61,7 +61,7 @@ echo:
?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 :
+ 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. 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 :
@@ -85,9 +85,9 @@ echo:
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
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.
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. 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) 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_dirmodule Html = Tiny_httpd_htmlAlias to Tiny_httpd_html
\ No newline at end of file
+ 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 : ?after_init:(unit -> unit) -> 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_dirmodule Html = Tiny_httpd_htmlAlias to Tiny_httpd_html
Tiny_httpd_server.HeadersThe 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 : tEmpty list of headers
val get : ?f:(string -> string) -> string -> t -> string optionget k headers looks for the header field with key k.
set k v headers sets the key k to value v. It erases any previous entry for k
val contains : string -> t -> boolIs there a header with the given key?
val pp : Stdlib.Format.formatter -> t -> unitPretty print the headers.
Tiny_httpd_server.HeadersThe 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 : tEmpty list of headers.
val get : ?f:(string -> string) -> string -> t -> string optionget k headers looks for the header field with key k.
set k v headers sets the key k to value v. It erases any previous entry for k
val contains : string -> t -> boolIs there a header with the given key?
val pp : Stdlib.Format.formatter -> t -> unitPretty print the headers.
Tiny_httpd_server.MiddlewareA middleware can be inserted in a handler to modify or observe its behavior.
type handler = byte_stream Request.t -> resp:(Response.t -> unit) -> unitHandlers are functions returning a response to a request. The response can be delayed, hence the use of a continuation as the resp parameter.
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 : tTrivial middleware that does nothing.
Tiny_httpd_server.Middlewaretype handler = byte_stream Request.t -> resp:(Response.t -> unit) -> unitHandlers are functions returning a response to a request. The response can be delayed, hence the use of a continuation as the resp parameter.
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 : tTrivial middleware that does nothing.
Tiny_httpd_server.Requesttype 'body t = private {meth : Meth.t;host : string;headers : Headers.t;http_version : int * int;path : string;path_components : string list;query : (string * string) list;body : 'body;start_time : float;}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.
val pp : Stdlib.Format.formatter -> string t -> unitPretty print the request and its body
val pp_ : Stdlib.Format.formatter -> _ t -> unitPretty print the request without its body
val get_header : ?f:(string -> string) -> _ t -> string -> string optionval get_header_int : _ t -> string -> int optionset_header k v req sets k: v in the request req's headers.
val host : _ t -> stringHost field of the request. It also appears in the headers.
val path : _ t -> stringRequest path.
val body : 'b t -> 'bRequest body, possibly empty.
val start_time : _ t -> floattime stamp (from Unix.gettimeofday) after parsing the first line of the request
val limit_body_size : max_size:int -> byte_stream t -> byte_stream tLimit the body size to max_size bytes, or return a 413 error.
val read_body_full : ?buf_size:int -> byte_stream t -> string tRead the whole body into a string. Potentially blocking.
Tiny_httpd_server.Requesttype 'body t = private {meth : Meth.t;HTTP method for this request.
*)host : string;headers : Headers.t;List of headers.
*)http_version : int * int;HTTP version. This should be either 1, 0 or 1, 1.
path : string;Full path of the requested URL.
*)path_components : string list;Components of the path of the requested URL.
*)query : (string * string) list;Query part of the requested URL.
*)body : 'body;Body of the request.
*)start_time : float;}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.
val pp : Stdlib.Format.formatter -> string t -> unitPretty print the request and its body. The exact format of this printing is not specified.
val pp_ : Stdlib.Format.formatter -> _ t -> unitPretty print the request without its body. The exact format of this printing is not specified.
val get_header : ?f:(string -> string) -> _ t -> string -> string optionget_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 optionSame as get_header but also performs a string to integer conversion.
set_header k v req sets k: v in the request req's headers.
Modify headers using the given function.
val host : _ t -> stringHost field of the request. It also appears in the headers.
val path : _ t -> stringRequest path.
val body : 'b t -> 'bRequest body, possibly empty.
val start_time : _ t -> floattime stamp (from Unix.gettimeofday) after parsing the first line of the request
val limit_body_size : max_size:int -> byte_stream t -> byte_stream tLimit the body size to max_size bytes, or return a 413 error.
val read_body_full : ?buf_size:int -> byte_stream t -> string tRead the whole body into a string. Potentially blocking.
Tiny_httpd_server.ResponseBody of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events).
type t = private {code : Response_code.t;headers : Headers.t;Headers of the reply. Some will be set by Tiny_httpd automatically.
body : body;Body of the response. Can be empty.
*)}A response to send back to a client.
val set_code : Response_code.t -> t -> tSet the response code.
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> tMake a response from its raw components, with a string body. Use "" to not send a body at all.
val make_raw_stream :
+Response (tiny_httpd.Tiny_httpd_server.Response) Module Tiny_httpd_server.Response
Body of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events notably).
type t = private {code : Response_code.t;headers : Headers.t;(*Headers of the reply. Some will be set by Tiny_httpd automatically.
*)body : body;(*Body of the response. Can be empty.
*)
}A response to send back to a client.
val set_code : Response_code.t -> t -> tSet the response code.
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> tMake 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 ->
@@ -16,4 +16,4 @@
?headers:Headers.t ->
code:int ->
('a, unit, string, t) Stdlib.format4 ->
- 'aMake the current request fail with the given code and message. Example: fail ~code:404 "oh noes, %s not found" "waldo".
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 -> unitPretty print the response.
\ No newline at end of file
+ 'aMake the current request fail with the given code and message. Example: fail ~code:404 "oh noes, %s not found" "waldo".
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 -> unitPretty print the response. The exact format is not specified.
Tiny_httpd_server.RouteBasic type-safe routing.
val int : (int -> 'a, 'a) compMatches an integer.
val string : (string -> 'a, 'a) compMatches a string not containing '/' and binds it as is.
val string_urlencoded : (string -> 'a, 'a) compMatches a URL-encoded string, and decodes it.
val exact : string -> ('a, 'a) compexact "s" matches "s" and nothing else.
val return : ('a, 'a) tMatches the empty path.
val rest_of_path : (string -> 'a, 'a) tMatches a string, even containing '/'. This will match the entirety of the remaining route.
val rest_of_path_urlencoded : (string -> 'a, 'a) tMatches a string, even containing '/', an URL-decode it. This will match the entirety of the remaining route.
comp / route matches "foo/bar/…" iff comp matches "foo", and route matches "bar/…".
exact_path "foo/bar/..." r is equivalent to exact "foo" @/ exact "bar" @/ ... @/ r
val pp : Stdlib.Format.formatter -> (_, _) t -> unitPrint the route.
val to_string : (_, _) t -> stringPrint the route.
Tiny_httpd_server.Routeval int : (int -> 'a, 'a) compMatches an integer.
val string : (string -> 'a, 'a) compMatches a string not containing '/' and binds it as is.
val string_urlencoded : (string -> 'a, 'a) compMatches a URL-encoded string, and decodes it.
val exact : string -> ('a, 'a) compexact "s" matches "s" and nothing else.
val return : ('a, 'a) tMatches the empty path.
val rest_of_path : (string -> 'a, 'a) tMatches a string, even containing '/'. This will match the entirety of the remaining route.
val rest_of_path_urlencoded : (string -> 'a, 'a) tMatches a string, even containing '/', an URL-decode it. This will match the entirety of the remaining route.
comp / route matches "foo/bar/…" iff comp matches "foo", and route matches "bar/…".
exact_path "foo/bar/..." r is equivalent to exact "foo" @/ exact "bar" @/ ... @/ r
val pp : Stdlib.Format.formatter -> (_, _) t -> unitPrint the route.
val to_string : (_, _) t -> stringPrint the route.
Tiny_httpd_serverHTTP 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.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 :
+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.tHTTP Methods
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. From the point of view of the server, they're inputs.
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 ... endRouting
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.
module Route : sig ... endMiddlewares
A middleware can be inserted in a handler to modify or observe its behavior.
module Middleware : sig ... endMain Server type
A HTTP server. See create for more details.
val create :
?masksigpipe:bool ->
?max_connections:int ->
?timeout:float ->
@@ -11,7 +11,7 @@
?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 :
+ 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. 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 :
@@ -35,9 +35,9 @@
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 = sig ... endA server-side function to generate of Server-sent events.
type server_sent_generator = (module SERVER_SENT_GENERATOR)Server-sent event generator
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.
Server-sent events
EXPERIMENTAL: this API is not stable yet.
module type SERVER_SENT_GENERATOR = sig ... endA 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) 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.
\ No newline at end of file
+ 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).
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 : ?after_init:(unit -> unit) -> 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.
Tiny_httpd_streamByte 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;mutable len : int;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;}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_fd : ?buf_size:int -> Unix.file_descr -> tMake a buffered stream from the given file descriptor.
val of_fd_close_noerr : ?buf_size:int -> Unix.file_descr -> tSame as of_fd 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 :
+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.
type t = {mutable bs : bytes;(*The bytes
*)mutable off : int;mutable len : int;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;
}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_fd : ?buf_size:int -> Unix.file_descr -> tMake a buffered stream from the given file descriptor.
val of_fd_close_noerr : ?buf_size:int -> Unix.file_descr -> tSame as of_fd 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) ->
diff --git a/dev/tiny_httpd/index.html b/dev/tiny_httpd/index.html
index 9259b96f..e36e7060 100644
--- a/dev/tiny_httpd/index.html
+++ b/dev/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 Byte streams.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 Http ServerTiny_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
diff --git a/dev/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html b/dev/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html
index 63fa1255..1cf17118 100644
--- a/dev/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html
+++ b/dev/tiny_httpd_camlzip/Tiny_httpd_camlzip/index.html
@@ -1,6 +1,6 @@
-Tiny_httpd_camlzip (tiny_httpd_camlzip.Tiny_httpd_camlzip) Module Tiny_httpd_camlzip
val middleware :
+Tiny_httpd_camlzip (tiny_httpd_camlzip.Tiny_httpd_camlzip) Module Tiny_httpd_camlzip
Middleware for compression.
This uses camlzip to provide deflate compression/decompression. If installed, the middleware will compress responses' bodies when they are streams or fixed-size above a given limit (but it will not compress small, fixed-size bodies).
val middleware :
?compress_above:int ->
?buf_size:int ->
unit ->
- Tiny_httpd_server.Middleware.tMiddleware responsible for deflate compression/decompression.
val setup : ?compress_above:int -> ?buf_size:int -> Tiny_httpd_server.t -> unitInstall middleware for tiny_httpd to be able to encode/decode compressed streams
\ No newline at end of file
+ Tiny_httpd_server.Middleware.tMiddleware responsible for deflate compression/decompression.
val setup : ?compress_above:int -> ?buf_size:int -> Tiny_httpd_server.t -> unitInstall middleware for tiny_httpd to be able to encode/decode compressed streams
\ No newline at end of file