From defad49bf5d7d658f341293d07c04d0ea4ea55fa Mon Sep 17 00:00:00 2001 From: c-cube Date: Wed, 30 Mar 2022 16:27:48 +0000 Subject: [PATCH] deploy: b8210b29156960f1587ddd4ddeb9f37a68f21928 --- dev/tiny_httpd/Tiny_httpd/index.html | 10 +++++----- dev/tiny_httpd/Tiny_httpd_server/index.html | 2 +- dev/tiny_httpd/Tiny_httpd_stream/index.html | 2 +- dev/tiny_httpd/index.html | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dev/tiny_httpd/Tiny_httpd/index.html b/dev/tiny_httpd/Tiny_httpd/index.html index 9012e172..67296d28 100644 --- a/dev/tiny_httpd/Tiny_httpd/index.html +++ b/dev/tiny_httpd/Tiny_httpd/index.html @@ -1,5 +1,5 @@ -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
+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_buf

Generic 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_stream

Main Server Type

include module type of struct include Tiny_httpd_server end
type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t

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.

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

Main Server Type

type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t
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.

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
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 -> @@ -72,7 +72,7 @@ echo: stage:[ `Encoding | `Stage of int ] -> t -> Middleware.t -> - unit

Add a middleware to every request/response pair.

  • parameter stage

    specify when middleware applies. Encoding comes first (outermost layer), then stages in increasing order.

  • raises Invalid_argument

    if stage is `Stage n where n < 1

  • since 0.11

Request handlers

val set_top_handler : t -> ( string Request.t -> Response.t ) -> unit

Setup 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 : + unit

Add a middleware to every request/response pair.

  • parameter stage

    specify when middleware applies. Encoding comes first (outermost layer), then stages in increasing order.

  • raises Invalid_argument

    if stage is `Stage n where n < 1

  • since 0.11
Request handlers
val set_top_handler : t -> ( string Request.t -> Response.t ) -> unit

Setup 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 -> @@ -88,10 +88,10 @@ echo: t -> ( 'a, byte_stream Request.t -> Response.t ) Route.t -> 'a -> - unit

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.

  • since 0.6

Server-sent events

EXPERIMENTAL: this API is not stable yet.

module type SERVER_SENT_GENERATOR = Tiny_httpd_server.SERVER_SENT_GENERATOR

A server-side function to generate of Server-sent events.

type server_sent_generator = (module SERVER_SENT_GENERATOR)

Server-sent event generator

  • since 0.9
val add_route_server_sent_handler : + unit

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.

  • since 0.6
Server-sent events

EXPERIMENTAL: this API is not stable yet.

module type SERVER_SENT_GENERATOR = Tiny_httpd_server.SERVER_SENT_GENERATOR

A server-side function to generate of Server-sent events.

type server_sent_generator = (module SERVER_SENT_GENERATOR)

Server-sent event generator

  • since 0.9
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 -> - 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 : 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.

Utils

module Util = Tiny_httpd_util

Static directory serving

module Dir = Tiny_httpd_dir
\ 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 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 : 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.

Utils

module Util = Tiny_httpd_util

Static directory serving

module Dir = Tiny_httpd_dir
\ 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 9d43811b..943e8a28 100644 --- a/dev/tiny_httpd/Tiny_httpd_server/index.html +++ b/dev/tiny_httpd/Tiny_httpd_server/index.html @@ -1,5 +1,5 @@ -Tiny_httpd_server (tiny_httpd.Tiny_httpd_server)

Module Tiny_httpd_server

HTTP 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.t
type byte_stream = Tiny_httpd_stream.t

Methods

module Meth : sig ... end

Headers

Headers are metadata associated with a request or response.

module Headers : sig ... end

Requests

Requests are sent by a client, e.g. a web browser or cURL.

module Request : sig ... end

Response Codes

module Response_code : sig ... end

Responses

Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t

module Response : sig ... end
module Route : sig ... end
module Middleware : sig ... end

Main Server type

type t

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

  • since NEXT_RELEASE
type buf = Tiny_httpd_buf.t
type byte_stream = Tiny_httpd_stream.t

Methods

module Meth : sig ... end

Headers

Headers are metadata associated with a request or response.

module Headers : sig ... end

Requests

Requests are sent by a client, e.g. a web browser or cURL.

module Request : sig ... end

Response Codes

module Response_code : sig ... end

Responses

Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t

module Response : sig ... end
module Route : sig ... end
module Middleware : sig ... end

Main Server type

type t

A HTTP server. See create for more details.

val create : ?masksigpipe:bool -> ?max_connections:int -> ?timeout:float -> diff --git a/dev/tiny_httpd/Tiny_httpd_stream/index.html b/dev/tiny_httpd/Tiny_httpd_stream/index.html index b85d125d..016dcf30 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

type hidden
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 -> unit
val empty : t
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_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.

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 = {
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 -> 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_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 : ?bs:bytes -> ?close:( t -> unit ) -> consume:( t -> int -> unit ) -> diff --git a/dev/tiny_httpd/index.html b/dev/tiny_httpd/index.html index 279c1063..28094494 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