package dream_middleware_ext

  1. Overview
  2. Docs

Fixed Window algorithm.

type t

The type of fixed window

type fw_conf

The type of fixed window configuration

type fw_store

The type of fixed window container

exception InvalidLimit of string
exception InvalidTimeWindow of string
val make_fw_conf : limit:int64 -> secs:float -> return_headers:bool -> fw_conf

make_fw_conf m n o makes a configuration of window of n seconds which contains m request permits, and boolean o returns X-Rate-Limit-* headers conditionally

val make_fw_store : fw_conf -> fw_store

make_fw_store conf makes a global fixed window container

val make_fw_rate_limiter : conf:fw_conf -> store:fw_store -> ?err_msg:string -> Dream.handler -> Dream.request -> Dream.response Lwt.t

make_fw_rate_limiter m n o makes a fixed window middleware that takes a m configuration and a n global fixed windown container, and a boolean o returns custom Too_Many_Requests message

OCaml

Innovation. Community. Security.