package dream_middleware_ext

  1. Overview
  2. Docs

Token Bucket algorithm.

type t

The type of token bucket

type tb_conf

The type of token bucket configuration

type tb_bucket

The type of token bucket container

exception InvalidBucketSize of string
exception InvalidRefillCount of string
exception InvalidRefillRate of string
val make_tb_conf : bucket_size:int64 -> refill_count:int64 -> refill_interval:float -> tb_conf

make_tb_conf m n o makes a configuration of initial bucket size m, and refills the bucket for n counts every o seconds

val make_tb_bucket : tb_conf -> tb_bucket

make_tb_bucket conf makes a global token bucket

val make_tb_rate_limiter : conf:tb_conf -> bucket:tb_bucket -> ?err_msg:string -> Dream.handler -> Dream.request -> Dream.response Lwt.t

make_tb_rate_limiter m n o makes a token bucket middleware that takes a m configuration and a n global token bucket, and a boolean o returns custom Too_Many_Requests message

OCaml

Innovation. Community. Security.