diff --git a/tiny_httpd/Tiny_httpd/index.html b/tiny_httpd/Tiny_httpd/index.html index a72d3e7f..696f6f71 100644 --- a/tiny_httpd/Tiny_httpd/index.html +++ b/tiny_httpd/Tiny_httpd/index.html @@ -50,11 +50,12 @@ echo: 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_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
exception Bad_req of int * string

Exception raised to exit request handlers with a code+error message

Middlewares

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

module Middleware = Server.Middleware
module Head_middleware = Server.Head_middleware

A middleware that only considers the request's head+headers.

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 : + ?enable_logging:bool -> ?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

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)

  • parameter enable_logging

    if true and Logs is installed, emit logs via Logs (since NEXT_RELEASE). Default true.

  • 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 @@ -114,6 +115,7 @@ echo: ('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 : + ?enable_logging:bool -> ?masksigpipe:bool -> ?max_connections:int -> ?timeout:float -> @@ -125,4 +127,4 @@ echo: ?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 except when on Windows, which defaults to false.

  • 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.

+ 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.

diff --git a/tiny_httpd/Tiny_httpd_core/Log/index.html b/tiny_httpd/Tiny_httpd_core/Log/index.html index 872b7497..d8f8953a 100644 --- a/tiny_httpd/Tiny_httpd_core/Log/index.html +++ b/tiny_httpd/Tiny_httpd_core/Log/index.html @@ -5,4 +5,4 @@ ((('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.

val dummy : bool
+ unit
val setup : debug:bool -> unit -> unit

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

val dummy : bool
val fully_disable : unit -> unit

Totally silence logs for tiny_httpd. With Logs installed this means setting the level of the tiny_httpd source to None.

diff --git a/tiny_httpd/Tiny_httpd_core/Server/index.html b/tiny_httpd/Tiny_httpd_core/Server/index.html index e777ff37..93832b94 100644 --- a/tiny_httpd/Tiny_httpd_core/Server/index.html +++ b/tiny_httpd/Tiny_httpd_core/Server/index.html @@ -1,10 +1,11 @@ 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.

exception Bad_req of int * string

Exception raised to exit request handlers with a code+error message

Middlewares

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

module Middleware : sig ... end
module Head_middleware : sig ... end

A middleware that only considers the request's head+headers.

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 : + ?enable_logging:bool -> ?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

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)

  • parameter enable_logging

    if true and Logs is installed, emit logs via Logs (since NEXT_RELEASE). Default true.

  • 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 :