diff --git a/tiny_httpd/Tiny_httpd/index.html b/tiny_httpd/Tiny_httpd/index.html index 0c87bac0..a65e9ff0 100644 --- a/tiny_httpd/Tiny_httpd/index.html +++ b/tiny_httpd/Tiny_httpd/index.html @@ -49,7 +49,7 @@ echo: Accept: */* Content-Length: 10 Content-Type: application/x-www-form-urlencoded; - 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 :
+ 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.Middlewaremodule Head_middleware = Server.Head_middlewareA middleware that only considers the request's head+headers.
type 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) ->
@@ -100,6 +100,7 @@ echo:
?accept:
(unit Tiny_httpd_core.Request.t ->
(unit, Tiny_httpd_core.Response_code.t * string) result) ->
+ ?middlewares:Head_middleware.t list ->
t ->
('a, string Tiny_httpd_core.Request.t -> server_sent_generator -> unit)
Tiny_httpd_core.Route.t ->
@@ -108,6 +109,7 @@ echo:
?accept:
(unit Tiny_httpd_core.Request.t ->
(unit, Tiny_httpd_core.Response_code.t * string) result) ->
+ ?middlewares:Head_middleware.t list ->
t ->
('a, upgrade_handler) Tiny_httpd_core.Route.t ->
'a ->
diff --git a/tiny_httpd/Tiny_httpd_core/Server/Head_middleware/index.html b/tiny_httpd/Tiny_httpd_core/Server/Head_middleware/index.html
new file mode 100644
index 00000000..94acc512
--- /dev/null
+++ b/tiny_httpd/Tiny_httpd_core/Server/Head_middleware/index.html
@@ -0,0 +1,2 @@
+
+Head_middleware (tiny_httpd.Tiny_httpd_core.Server.Head_middleware) Module Server.Head_middleware
A middleware that only considers the request's head+headers.
These middlewares are simpler than full Middleware.t and work in more contexts.
A handler that takes the request, without its body, and possibly modifies it.
val to_middleware : t -> Middleware.t
diff --git a/tiny_httpd/Tiny_httpd_core/Server/index.html b/tiny_httpd/Tiny_httpd_core/Server/index.html
index 75deb950..675c26b0 100644
--- a/tiny_httpd/Tiny_httpd_core/Server/index.html
+++ b/tiny_httpd/Tiny_httpd_core/Server/index.html
@@ -1,5 +1,5 @@
-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.
Middlewares
A middleware can be inserted in a handler to modify or observe its behavior.
module Middleware : sig ... endMain Server type
module type IO_BACKEND = sig ... endA backend that provides IO operations, network operations, etc.
val create_from :
+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.
Middlewares
A middleware can be inserted in a handler to modify or observe its behavior.
module Middleware : sig ... endmodule Head_middleware : sig ... endA middleware that only considers the request's head+headers.
Main Server type
module type IO_BACKEND = sig ... endA 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) ->
@@ -30,11 +30,13 @@
'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. 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) ->
+ ?middlewares:Head_middleware.t list ->
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).
Upgrade handlers
These handlers upgrade the connection to another protocol.
module type UPGRADE_HANDLER = sig ... endHandler 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) ->
+ ?middlewares:Head_middleware.t list ->
t ->
('a, upgrade_handler) Route.t ->
'a ->