Module Webs_http11_gateway

HTTP/1.1 gateway connector.

This connector serves a bounded number of concurrent HTTP/1.1 requests using one Thread per request drawn from a thread pool.

See the HTTP service howto for instructions to use this connector with an HTTP gateway.

Warning. This should only ever be used behind a proper HTTP gateway or on localhost for development. In particular:


val default_max_connections : int

default_max_connection is 100.

type t

The type for HTTP/1.1 gateway connectors.

val make : ?listener:Webs_listener.t -> ?log:(Webs.Http.Connector.Log.msg -> unit) -> ?max_connections:int -> ?max_request_body_byte_size:int -> ?max_request_headers_byte_size:int -> ?service_path:Webs.Http.Path.t -> unit -> t

make () is a new connector with:

val listener : t -> Webs_listener.t

listener c is the connection listener of c. See make.

val log : t -> Webs.Http.Connector.Log.msg -> unit

log c is the log of c. See make.

val max_connections : t -> int

max_connection c is the maximal number of concurrent connections for c. See make.

val max_request_body_byte_size : t -> int

max_request_body_byte_size c is the maximal body size in bytes for requests handled by c. Warning not enforced for now. See make.

val max_request_headers_byte_size : t -> int

max_request_headers_byte_size c is the maximal headers size in bytes for requests handled by c. See make.

val service_path : t -> Webs.Http.Path.t

service_path c is the service path of c. The path on which the root of the service is served by the gateway. See Webs.Http.Request.service_path.

val serving : t -> bool

serving c is true iff c a serve is going on.


val serve : ?handle_stop_sigs:bool -> t -> (Webs.Http.Request.t -> Webs.Http.Response.t) -> (unit, string) Stdlib.result

serve c service runs the service service with connector c.

If serving c is true this returns immedialy with Ok (). Otherwise this blocks and serves requests by calling service in a thread drawn from a thread pool limited by max_connections until either:

  • stop is called on c
  • A SIGINT or SIGTERM signal is received when handle_stop_sigs is true (default).

The function waits for ongoing requests to finish before returning. After the function returns it is possible to call serve again on c.

The connector supports:

Signals. When serve is entered and handle_stop_sigs is true (default), Stdlib.Sys.sigpipe is made to be ignored and a handler calling stop c is installed on Stdlib.Sys.sigint and Stdlib.Sys.sigstop. The signal handling that existed before the function was called is restored when the function returns.

val stop : t -> unit

stop c stops c. If serving c is true this makes it stop accepting new connections, waits for the last requests to finish and unblocks the serve call.