Module Webs_httpc

HTTP/1.1 gateway connector.

This connector serves an unbounded number of 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.

Connector

type t

The type for HTTP/1.1 connectors. Implemented using one Thread per connection.

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.
  • 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 listener : t -> Webs_unix.listener

listener c is the connector connection listener.

val serve : 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.

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. The previous value is 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.

TODO. At the moment this does not ensure all connections get terminated cleanly.