package naboris

  1. Overview
  2. Docs

Module for configuring the naboris http server.

type 'sessionData 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 setSessionConfig : ?maxAge:int -> ?sidKey:string -> (string option -> 'sessionData Session.t option Lwt.t) -> 'sessionData t -> 'sessionData t

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

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

~maxAge Optional param to set max age for session cookies in seconds (defaults to 30 days) ~sidKey Optional param to set key for session cookies (defaults to "nab.sid")

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

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

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 -> Res.t Lwt.t) -> Route.t -> 'sessionData Req.t -> Res.t -> Res.t 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 addStaticMiddleware : string list -> string -> 'sessionData t -> 'sessionData t

Creates a virtual path prefix list(string) and maps it to a local directory string.

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

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

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

val middlewares : 'sessionData t -> ((Route.t -> 'sessionData Req.t -> Res.t -> Res.t Lwt.t) -> Route.t -> 'sessionData Req.t -> Res.t -> Res.t 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 -> Res.t 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.

OCaml

Innovation. Community. Security.