diff --git a/dev/tiny_httpd/Tiny_httpd/index.html b/dev/tiny_httpd/Tiny_httpd/index.html index ac95d6cd..0b3a4921 100644 --- a/dev/tiny_httpd/Tiny_httpd/index.html +++ b/dev/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"}

Tiny buffer implementation

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

module Buf = Tiny_httpd_buf

Generic byte streams

module Byte_stream = Tiny_httpd_stream

Main Server Type

type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t
HTTP Methods
Headers

Headers are metadata associated with a request or response.

module Headers = Tiny_httpd_server.Headers
Requests

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.Request
Response Codes
module Response_code = Tiny_httpd_server.Response_code
Responses

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.Response
Routing

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.

Middlewares

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

module Middleware = Tiny_httpd_server.Middleware
Main Server type

A 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_buf

Generic byte streams

module Byte_stream = Tiny_httpd_stream

IO Abstraction

module IO = Tiny_httpd_io

Main Server Type

type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t
HTTP Methods
Headers

Headers are metadata associated with a request or response.

module Headers = Tiny_httpd_server.Headers
Requests

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.Request
Response Codes
module Response_code = Tiny_httpd_server.Response_code
Responses

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.Response
Routing

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.

  • since 0.6
Middlewares

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

  • since 0.11
module Middleware = Tiny_httpd_server.Middleware
Main Server type

A HTTP server. See create for more details.

val create : ?masksigpipe:bool -> ?max_connections:int -> ?timeout:float -> @@ -61,7 +61,12 @@ echo: ?sock:Unix.file_descr -> ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> unit -> - t

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

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

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

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

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

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

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

module type IO_BACKEND = Tiny_httpd_server.IO_BACKEND

A 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 -> + 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 NEXT_RELEASE
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 * (byte_stream -> byte_stream)) 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 : @@ -90,4 +95,4 @@ echo: t -> ('a, string Request.t -> server_sent_generator -> unit) Route.t -> 'a -> - unit

Add 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).

  • since 0.9
Run the server
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) Stdlib.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 .

Utils

module Util = Tiny_httpd_util

Static directory serving

module Dir = Tiny_httpd_dir
module Html = Tiny_httpd_html
\ No newline at end of file + unit

Add 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).

  • since 0.9
Run the server
val running : t -> bool

Is the server running?

  • since NEXT_RELEASE
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) Stdlib.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 .

Utils

module Util = Tiny_httpd_util

Static directory serving

module Dir = Tiny_httpd_dir
module Html = Tiny_httpd_html
\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_buf/index.html b/dev/tiny_httpd/Tiny_httpd_buf/index.html index 5d7fe5d6..d8ee3bba 100644 --- a/dev/tiny_httpd/Tiny_httpd_buf/index.html +++ b/dev/tiny_httpd/Tiny_httpd_buf/index.html @@ -1,2 +1,2 @@ -Tiny_httpd_buf (tiny_httpd.Tiny_httpd_buf)

Module Tiny_httpd_buf

Simple buffer.

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

type t
val size : t -> int
val clear : t -> unit
val create : ?size:int -> unit -> t
val contents : t -> string
val bytes_slice : t -> bytes

Access underlying slice of bytes.

  • since 0.5
val contents_and_clear : t -> string

Get contents of the buffer and clear it.

  • since 0.5
val add_bytes : t -> bytes -> int -> int -> unit

Append given bytes slice to the buffer.

  • since 0.5
\ No newline at end of file +Tiny_httpd_buf (tiny_httpd.Tiny_httpd_buf)

Module Tiny_httpd_buf

Simple buffer.

These buffers are used to avoid allocating too many byte arrays when processing streams and parsing requests.

type t
val size : t -> int
val clear : t -> unit
val create : ?size:int -> unit -> t
val contents : t -> string
val bytes_slice : t -> bytes

Access underlying slice of bytes.

  • since 0.5
val contents_and_clear : t -> string

Get contents of the buffer and clear it.

  • since 0.5
val add_bytes : t -> bytes -> int -> int -> unit

Append given bytes slice to the buffer.

  • since 0.5
val add_string : t -> string -> unit

Add string.

  • since NEXT_RELEASE
val add_buffer : t -> Stdlib.Buffer.t -> unit

Append bytes from buffer.

  • since NEXT_RELEASE
\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_html_/A/index.html b/dev/tiny_httpd/Tiny_httpd_html_/A/index.html deleted file mode 100644 index 48a2a04e..00000000 --- a/dev/tiny_httpd/Tiny_httpd_html_/A/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -A (tiny_httpd.Tiny_httpd_html_.A)

Module Tiny_httpd_html_.A

Attributes.

This module contains combinator for the standard attributes. One can also just use a pair of strings.

type t = string -> attribute

Attribute builder

val accept : t

Attribute "accept".

val accept_charset : t

Attribute "accept-charset".

val accesskey : t

Attribute "accesskey".

val action : t

Attribute "action".

val align : t

Attribute "align".

val allow : t

Attribute "allow".

val alt : t

Attribute "alt".

val async : t

Attribute "async".

val autocapitalize : t

Attribute "autocapitalize".

val autocomplete : t

Attribute "autocomplete".

val autofocus : t

Attribute "autofocus".

val autoplay : t

Attribute "autoplay".

val buffered : t

Attribute "buffered".

val capture : t

Attribute "capture".

val challenge : t

Attribute "challenge".

val charset : t

Attribute "charset".

val checked : t

Attribute "checked".

val cite : t

Attribute "cite".

val class_ : t

Attribute "class".

val code : t

Attribute "code".

val codebase : t

Attribute "codebase".

val cols : t

Attribute "cols".

val colspan : t

Attribute "colspan".

val content : t

Attribute "content".

val contenteditable : t

Attribute "contenteditable".

val contextmenu : t

Attribute "contextmenu".

val controls : t

Attribute "controls".

val coords : t

Attribute "coords".

val crossorigin : t

Attribute "crossorigin".

val csp : t

Attribute "csp".

val data : t

Attribute "data".

val data_star : t

Attribute "data-*".

val datetime : t

Attribute "datetime".

val decoding : t

Attribute "decoding".

val default : t

Attribute "default".

val defer : t

Attribute "defer".

val dir : t

Attribute "dir".

val dirname : t

Attribute "dirname".

val disabled : t

Attribute "disabled".

val download : t

Attribute "download".

val draggable : t

Attribute "draggable".

val enctype : t

Attribute "enctype".

val enterkeyhint : t

Attribute "enterkeyhint".

val for_ : t

Attribute "for".

val form : t

Attribute "form".

val formaction : t

Attribute "formaction".

val formenctype : t

Attribute "formenctype".

val formmethod : t

Attribute "formmethod".

val formnovalidate : t

Attribute "formnovalidate".

val formtarget : t

Attribute "formtarget".

val headers : t

Attribute "headers".

val hidden : t

Attribute "hidden".

val high : t

Attribute "high".

val href : t

Attribute "href".

val hreflang : t

Attribute "hreflang".

val http_equiv : t

Attribute "http-equiv".

val icon : t

Attribute "icon".

val id : t

Attribute "id".

val importance : t

Attribute "importance".

val integrity : t

Attribute "integrity".

val ismap : t

Attribute "ismap".

val itemprop : t

Attribute "itemprop".

val keytype : t

Attribute "keytype".

val kind : t

Attribute "kind".

val label : t

Attribute "label".

val lang : t

Attribute "lang".

val language : t

Attribute "language".

val list : t

Attribute "list".

val loop : t

Attribute "loop".

val low : t

Attribute "low".

val manifest : t

Attribute "manifest".

val max : t

Attribute "max".

val maxlength : t

Attribute "maxlength".

val minlength : t

Attribute "minlength".

val media : t

Attribute "media".

val method_ : t

Attribute "method".

val min : t

Attribute "min".

val multiple : t

Attribute "multiple".

val muted : t

Attribute "muted".

val name : t

Attribute "name".

val novalidate : t

Attribute "novalidate".

val open_ : t

Attribute "open".

val optimum : t

Attribute "optimum".

val pattern : t

Attribute "pattern".

val ping : t

Attribute "ping".

val placeholder : t

Attribute "placeholder".

val poster : t

Attribute "poster".

val preload : t

Attribute "preload".

val radiogroup : t

Attribute "radiogroup".

val readonly : t

Attribute "readonly".

val referrerpolicy : t

Attribute "referrerpolicy".

val rel : t

Attribute "rel".

val required : t

Attribute "required".

val reversed : t

Attribute "reversed".

val rows : t

Attribute "rows".

val rowspan : t

Attribute "rowspan".

val sandbox : t

Attribute "sandbox".

val scope : t

Attribute "scope".

val scoped : t

Attribute "scoped".

val selected : t

Attribute "selected".

val shape : t

Attribute "shape".

val size : t

Attribute "size".

val sizes : t

Attribute "sizes".

val slot : t

Attribute "slot".

val span : t

Attribute "span".

val spellcheck : t

Attribute "spellcheck".

val src : t

Attribute "src".

val srcdoc : t

Attribute "srcdoc".

val srclang : t

Attribute "srclang".

val srcset : t

Attribute "srcset".

val start : t

Attribute "start".

val step : t

Attribute "step".

val style : t

Attribute "style".

val summary : t

Attribute "summary".

val tabindex : t

Attribute "tabindex".

val target : t

Attribute "target".

val title : t

Attribute "title".

val translate : t

Attribute "translate".

val text : t

Attribute "Text".

val type_ : t

Attribute "type".

val usemap : t

Attribute "usemap".

val value : t

Attribute "value".

val width : t

Attribute "width".

val wrap : t

Attribute "wrap".

\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_html_/Out/index.html b/dev/tiny_httpd/Tiny_httpd_html_/Out/index.html deleted file mode 100644 index e3a7915e..00000000 --- a/dev/tiny_httpd/Tiny_httpd_html_/Out/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -Out (tiny_httpd.Tiny_httpd_html_.Out)

Module Tiny_httpd_html_.Out

Output for HTML combinators.

This output type is used to produce a string reasonably efficiently from a tree of combinators.

type t
val create : unit -> t
val clear : t -> unit
val add_char : t -> char -> unit
val add_string : t -> string -> unit
val add_format_nl : t -> unit
val with_no_format_nl : t -> (unit -> 'a) -> 'a
val to_string : t -> string
\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_io/.dummy b/dev/tiny_httpd/Tiny_httpd_io/.dummy new file mode 100644 index 00000000..e69de29b diff --git a/dev/tiny_httpd/Tiny_httpd_io/In_channel/index.html b/dev/tiny_httpd/Tiny_httpd_io/In_channel/index.html new file mode 100644 index 00000000..9e66b392 --- /dev/null +++ b/dev/tiny_httpd/Tiny_httpd_io/In_channel/index.html @@ -0,0 +1,2 @@ + +In_channel (tiny_httpd.Tiny_httpd_io.In_channel)

Module Tiny_httpd_io.In_channel

type t = {
  1. input : bytes -> int -> int -> int;
    (*

    Read into the slice. Returns 0 only if the channel is closed.

    *)
  2. close : unit -> unit;
}
val of_in_channel : ?close_noerr:bool -> Stdlib.in_channel -> t
val of_unix_fd : ?close_noerr:bool -> Unix.file_descr -> t
val input : t -> bytes -> int -> int -> int
val close : t -> unit
\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_io/Out_channel/index.html b/dev/tiny_httpd/Tiny_httpd_io/Out_channel/index.html new file mode 100644 index 00000000..6255ce08 --- /dev/null +++ b/dev/tiny_httpd/Tiny_httpd_io/Out_channel/index.html @@ -0,0 +1,2 @@ + +Out_channel (tiny_httpd.Tiny_httpd_io.Out_channel)

Module Tiny_httpd_io.Out_channel

type t = {
  1. output : bytes -> int -> int -> unit;
    (*

    Output slice

    *)
  2. flush : unit -> unit;
    (*

    Flush underlying buffer

    *)
  3. close : unit -> unit;
}
val of_out_channel : ?close_noerr:bool -> Stdlib.out_channel -> t
val output : t -> bytes -> int -> int -> unit
val output_string : t -> string -> unit
val close : t -> unit
val flush : t -> unit
val output_buf : t -> Buf.t -> unit
\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_io/TCP_server/index.html b/dev/tiny_httpd/Tiny_httpd_io/TCP_server/index.html new file mode 100644 index 00000000..851c2a3c --- /dev/null +++ b/dev/tiny_httpd/Tiny_httpd_io/TCP_server/index.html @@ -0,0 +1,2 @@ + +TCP_server (tiny_httpd.Tiny_httpd_io.TCP_server)

Module Tiny_httpd_io.TCP_server

A TCP server abstraction

type conn_handler = {
  1. handle : In_channel.t -> Out_channel.t -> unit;
    (*

    Handle client connection

    *)
}
type t = {
  1. endpoint : unit -> string * int;
    (*

    Endpoint we listen on. This can only be called from within serve.

    *)
  2. active_connections : unit -> int;
    (*

    Number of connections currently active

    *)
  3. running : unit -> bool;
    (*

    Is the server currently running?

    *)
  4. stop : unit -> unit;
    (*

    Ask the server to stop. This might not take effect immediately.

    *)
}

Running server.

type builder = {
  1. serve : after_init:(t -> unit) -> handle:conn_handler -> unit -> unit;
    (*

    Blocking call to listen for incoming connections and handle them. Uses the connection handler to handle individual client connections.

    *)
}

A TCP server implementation.

\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_io/index.html b/dev/tiny_httpd/Tiny_httpd_io/index.html new file mode 100644 index 00000000..4aeaf718 --- /dev/null +++ b/dev/tiny_httpd/Tiny_httpd_io/index.html @@ -0,0 +1,2 @@ + +Tiny_httpd_io (tiny_httpd.Tiny_httpd_io)

Module Tiny_httpd_io

IO abstraction.

We abstract IO so we can support classic unix blocking IOs with threads, and modern async IO with Eio.

NOTE: experimental.

module Buf = Tiny_httpd_buf
module In_channel : sig ... end
module Out_channel : sig ... end
module TCP_server : sig ... end

A TCP server abstraction

\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_server/index.html b/dev/tiny_httpd/Tiny_httpd_server/index.html index f35f4045..3fca5dc0 100644 --- a/dev/tiny_httpd/Tiny_httpd_server/index.html +++ b/dev/tiny_httpd/Tiny_httpd_server/index.html @@ -11,7 +11,12 @@ ?sock:Unix.file_descr -> ?middlewares:([ `Encoding | `Stage of int ] * Middleware.t) list -> unit -> - t

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

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 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 = sig ... end

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

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.

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 * (byte_stream -> byte_stream)) 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 : @@ -40,4 +45,4 @@ t -> ('a, string Request.t -> server_sent_generator -> unit) Route.t -> 'a -> - unit

Add 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 -> 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) Stdlib.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.

\ No newline at end of file + unit

Add 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 running : t -> bool

Is the server running?

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) Stdlib.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.

\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_server/module-type-IO_BACKEND/index.html b/dev/tiny_httpd/Tiny_httpd_server/module-type-IO_BACKEND/index.html new file mode 100644 index 00000000..f5d23fff --- /dev/null +++ b/dev/tiny_httpd/Tiny_httpd_server/module-type-IO_BACKEND/index.html @@ -0,0 +1,2 @@ + +IO_BACKEND (tiny_httpd.Tiny_httpd_server.IO_BACKEND)

Module type Tiny_httpd_server.IO_BACKEND

A backend that provides IO operations, network operations, etc.

val init_addr : unit -> string
val init_port : unit -> int
val spawn : (unit -> unit) -> unit

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.

val get_time_s : unit -> float

obtain the current timestamp in seconds.

val tcp_server : unit -> Tiny_httpd_io.TCP_server.builder

Server that can listen on a port and handle clients.

\ No newline at end of file diff --git a/dev/tiny_httpd/Tiny_httpd_stream/index.html b/dev/tiny_httpd/Tiny_httpd_stream/index.html index f875d92c..85823699 100644 --- a/dev/tiny_httpd/Tiny_httpd_stream/index.html +++ b/dev/tiny_httpd/Tiny_httpd_stream/index.html @@ -1,5 +1,5 @@ -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 hidden

Type used to make t unbuildable via a record literal. Use make instead.

type t = {
  1. mutable bs : bytes;
    (*

    The bytes

    *)
  2. mutable off : int;
    (*

    Beginning of valid slice in bs

    *)
  3. mutable len : int;
    (*

    Length of valid slice in bs. If len = 0 after a call to fill, then the stream is finished.

    *)
  4. 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.

    *)
  5. consume : int -> unit;
    (*

    Consume n bytes from the buffer. This should only be called with n <= len.

    *)
  6. close : unit -> unit;
    (*

    Close the stream.

    *)
  7. _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 -> unit

Close stream

val empty : t

Stream with 0 bytes inside

val of_chan : ?buf_size:int -> Stdlib.in_channel -> t

Make a buffered stream from the given channel.

val of_chan_close_noerr : ?buf_size:int -> Stdlib.in_channel -> t

Same as of_chan but the close method will never fail.

val of_fd : ?buf_size:int -> Unix.file_descr -> t

Make a buffered stream from the given file descriptor.

val of_fd_close_noerr : ?buf_size:int -> Unix.file_descr -> t

Same as of_fd but the close method will never fail.

val of_bytes : ?i:int -> ?len:int -> bytes -> t

A stream that just returns the slice of bytes starting from i and of length len.

val of_string : string -> t
val iter : (bytes -> int -> int -> unit) -> t -> unit

Iterate on the chunks of the stream

  • since 0.3
val to_chan : Stdlib.out_channel -> t -> unit

Write the stream to the channel.

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

  • since 0.12
type hidden

Type used to make t unbuildable via a record literal. Use make instead.

type t = {
  1. mutable bs : bytes;
    (*

    The bytes

    *)
  2. mutable off : int;
    (*

    Beginning of valid slice in bs

    *)
  3. mutable len : int;
    (*

    Length of valid slice in bs. If len = 0 after a call to fill, then the stream is finished.

    *)
  4. 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.

    *)
  5. consume : int -> unit;
    (*

    Consume n bytes from the buffer. This should only be called with n <= len.

    *)
  6. close : unit -> unit;
    (*

    Close the stream.

    *)
  7. _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.

val close : t -> unit

Close stream

val empty : t

Stream with 0 bytes inside

val of_input : ?buf_size:int -> Tiny_httpd_io.In_channel.t -> t

Make a buffered stream from the given channel.

  • since NEXT_RELEASE
val of_chan : ?buf_size:int -> Stdlib.in_channel -> t

Make a buffered stream from the given channel.

val of_chan_close_noerr : ?buf_size:int -> Stdlib.in_channel -> t

Same as of_chan but the close method will never fail.

val of_fd : ?buf_size:int -> Unix.file_descr -> t

Make a buffered stream from the given file descriptor.

val of_fd_close_noerr : ?buf_size:int -> Unix.file_descr -> t

Same as of_fd but the close method will never fail.

val of_bytes : ?i:int -> ?len:int -> bytes -> t

A stream that just returns the slice of bytes starting from i and of length len.

val of_string : string -> t
val iter : (bytes -> int -> int -> unit) -> t -> unit

Iterate on the chunks of the stream

  • since 0.3
val to_chan : Stdlib.out_channel -> t -> unit

Write the stream to the channel.

  • since 0.3
val to_chan' : Tiny_httpd_io.Out_channel.t -> t -> unit

Write to the IO channel.

  • since NEXT_RELEASE
val make : ?bs:bytes -> ?close:(t -> unit) -> consume:(t -> int -> unit) -> @@ -15,4 +15,4 @@ size:int -> too_short:(int -> unit) -> t -> - t

read_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.

  • parameter close_rec

    if true, closing the resulting stream also closes bs

  • parameter too_short

    is called if bs closes with still n bytes remaining

val output_chunked : Stdlib.out_channel -> t -> unit

Write the stream into the channel, using the chunked encoding.

\ No newline at end of file + t

read_exactly ~size bs returns a new stream that reads exactly size bytes from bs, and then closes.

  • parameter close_rec

    if true, closing the resulting stream also closes bs

  • parameter too_short

    is called if bs closes with still n bytes remaining

val output_chunked : Stdlib.out_channel -> t -> unit

Write the stream into the channel, using the chunked encoding.

val output_chunked' : Tiny_httpd_io.Out_channel.t -> t -> unit

Write the stream into the channel, using the chunked encoding.

  • since NEXT_RELEASE
\ No newline at end of file diff --git a/dev/tiny_httpd/index.html b/dev/tiny_httpd/index.html index a46521a6..7b372ec7 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:

\ No newline at end of file +index (tiny_httpd.index)

tiny_httpd index

Library tiny_httpd

This library exposes the following toplevel modules:

\ No newline at end of file