Module Webs_httpc

HTTP/1.1 gateway connector.

This connector serves a bounded number of concurrent requests by taking connection and HTTP/1.1 requests on a Webs_unix.listener. If only for https support, it should only ever be used behind an HTTP gateway or locally for development.

See the Web service howto manual for instructions to connect a minimal example to an HTTP gateway.


val default_max_connections : int

default_max_connection is 100.

type t

The type for HTTP/1.1 connectors. Each connection is served using one Thread drawn from a pool.

val create : ?log:(Webs.Connector.log_msg -> unit) -> ?max_connections:int -> ?max_req_headers_byte_size:int -> ?max_req_body_byte_size:int -> ?listener:Webs_unix.listener -> unit -> t

create () is a new connector with following parameters:

  • listen specifies the socket to listen to on. Defaults to Webs_unix.listener_localhost
  • max_connections is the maximal number of allowed concurrent connections (defaults to default_max_connections).
  • max_req_headers_byte_size is the maximal allowed size in bytes for to the request line and headers. Defaults to 64Ko.
  • max_req_body_byte_size is the maximal request body size in bytes. FIXME not enforced, unclear where this is to put the limit on, for streaming bodies, if we cut the line the service might end up being confused (but then it should also cater for that possibility).
  • log logs connector log messages. Defaults to Webs.Connector.default_log with trace messages.
val max_connections : t -> int

max_connection c is the maximal number of concurrent connections.

val listener : t -> Webs_unix.listener

listener c is the connector connection listener.

val serve : ?stop_on_sigint:bool -> t -> Webs.service -> (unit, string) Stdlib.result

serve c s runs service s with connector c. This blocks, serving requests with s until stop is called on c. If stop_on_sigint is true (default) a signal handler is installed during the call to gracefully stop the serve.

The Webs.Req.service_root of requests is decoded from the custom HTTP header x-service-root this should be set appropriately by your gateway.

Note that the server may respond before the request hits service, notably:

Signals. When serve is entered Stdlib.Sys.sigpipe is made to be ignored and a handler for Stldib.Sys.sigint is installed if stop_on_sigint is true. The previous values are restored when the function returns.

val stop : t -> unit

stop s stops s. If s is blocked on serve this makes it stop accepting new connection.