wai-middleware-throttle-0.2.1.0: WAI Middleware for Request Throttling

Copyright(c) 2015 Christopher Reichert
LicenseBSD3
MaintainerChristopher Reichert <creichert07@gmail.com>
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Middleware.Throttle

Description

Uses a Token Bucket algorithm (from the token-bucket package) to throttle WAI Requests.

Example

main = do
  st <- initThrottler
  let payload  = "{ "api": "return data" }"
      app = throttle defaultThrottleSettings st
              $ _ f -> f (responseLBS status200 [] payload)
  Warp.run 3000 app

Synopsis

Documentation

Wai Request Throttling Middleware

throttle :: ThrottleSettings -> WaiThrottle -> Application -> Application Source

WAI Request Throttling Middleware.

Uses a Requests remoteHost function to resolve the remote IP address.

Wai Throttle middleware state.

Essentially, a TVar with a HashMap for indexing remote IP address

Throttle settings and configuration

data ThrottleSettings Source

Settings which control various behaviors in the middleware.

Constructors

ThrottleSettings 

Fields

isThrottled :: !(Request -> IO Bool)

Determines whether the Request is throttled

onThrottled :: !(Word64 -> Response)

Function to run when the request is throttled.

The first argument is a Word64 containing the amount of microseconds until the next retry should be attempted

throttleRate :: !Integer

Rate

throttlePeriod :: !Integer
 
throttleBurst :: !Integer

Burst rate

defaultThrottleSettings :: ThrottleSettings Source

Default settings to throttle requests.