package naboris

  1. Overview
  2. Docs

Module for configuring the naboris http server.

type 'sessionData t
type 'sessionData sessionConfig = {
  1. getSession : string option -> 'sessionData Session.t option Lwt.t;
}
type httpAfConfig = {
  1. read_buffer_size : int;
  2. request_body_buffer_size : int;
  3. response_buffer_size : int;
  4. response_body_buffer_size : int;
}
val create : unit -> 'sessionData t

Returns default config. Used as the starting place to build the config.

val setOnListen : (unit -> unit) -> 'sessionData t -> 'sessionData t

Create new config from t('sessionData) with the onListen function unit => unit.

onListen function is called once the server is created successfully.

val setSessionGetter : (string option -> 'sessionData Session.t option Lwt.t) -> 'sessionData t -> 'sessionData t

Creates new config from t('sessionData) with sessionGetter function option(string) => Lwt.t(option(Session.t('sessionData))).

sessionGetter function is called at the very beginning of each request/response lifecycle. Used to set session data into the Req.t('sessionData) for use later in the request/response lifecycle.

val setRequestHandler : (Route.t -> 'sessionData Req.t -> Res.t -> unit Lwt.t) -> 'sessionData t -> 'sessionData t

Creates new config from t('sessionData) with requestHandler (Route.t, Req.t('sessionData), Res.t) => Lwt.t(unit).

requestHandler is the main handler function for responding to incoming http requests.

val setErrorHandler : (Unix.sockaddr -> Httpaf.Response.t option -> Httpaf.Server_connection.error -> (Httpaf.Headers.t -> [ `write ] Httpaf.Body.t) -> unit) -> 'sessionData t -> 'sessionData t

Creates new config from t('sessionData) with errorHandler ErrorHandler.t.

val setHttpAfConfig : httpAfConfig -> 'sessionData t -> 'sessionData t

Creates new config from t('sessionData) with httpAfConfig httpAfConfig.

val addMiddleware : ((Route.t -> 'sessionData Req.t -> Res.t -> unit Lwt.t) -> Route.t -> 'sessionData Req.t -> Res.t -> unit Lwt.t) -> 'sessionData t -> 'sessionData t

Creates nwe config from t('sessionData) with the added middleware Middleware.t('sessionData).

Middlewares are executed in the order they are added. The final "middleware" is the requestHandler.

val sessionConfig : 'sessionData t -> 'sessionData sessionConfig option

Returns sessionConfig('sessionData) from config. None if none is configured.

val middlewares : 'sessionData t -> ((Route.t -> 'sessionData Req.t -> Res.t -> unit Lwt.t) -> Route.t -> 'sessionData Req.t -> Res.t -> unit Lwt.t) list

Returns list of middlewares from the config.

val onListen : 'sessionData t -> unit -> unit

Returns onListen function of t.

val routeRequest : 'sessionData t -> Route.t -> 'sessionData Req.t -> Res.t -> unit Lwt.t

Returns routeRequest function of t.

val errorHandler : 'sessionData t -> (Unix.sockaddr -> Httpaf.Response.t option -> Httpaf.Server_connection.error -> (Httpaf.Headers.t -> [ `write ] Httpaf.Body.t) -> unit) option

Returns option(ErrorHandler.t) of t.

val httpAfConfig : 'sessionData t -> Httpaf.Config.t option

Returns option(HttpAf.Config.t) of t.