package dream_middleware_ext

  1. Overview
  2. Docs

Module Dream_middleware_ext.Traffic_filter

Traffic filter middleware

type traffic_filter_conf

The type of configuration for traffic filter

type filter_type =
  1. | Ips of ip_filter
  2. | Headers of string list
  3. | Cookies of string list
    (*

    The type of traffic filter: 1. Ips -> ip based filter , 2. Headers -> header based filter 3. Cookies -> cookie based filter

    *)
and ip_filter = {
  1. whitelist : string list;
  2. blacklist : string list;
  3. x_real_ip : bool;
}

The type of ip based filter that takes a whitelist and a blacklist, conditionally matching on X-REAL-IP header

type target_type =
  1. | RootAccess
  2. | PathList of string list
    (*

    The type of path target: 1. RootAccess -> i.e. "/", 2. PathList -> a list of paths

    *)
exception InvalidIp of string
exception OverlappingIps of string
exception InvalidTarget of string
exception EmptyHeaderList of string
exception EmptyCookieList of string
val make_traffic_filter_conf : filter_type:filter_type -> ?target:target_type -> unit -> traffic_filter_conf

make_traffic_filter_conf m n o makes a traffic filter configuration that takes a m filter type and a n target path

val make_traffic_filter : conf:traffic_filter_conf -> ?err_msg:string -> Dream.handler -> Dream.request -> Dream.response Lwt.t

make_traffic_filter m n makes a traffic filter middleware that takes a m configuration, and a boolean o returns custom Unauthorized message