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

Copyright(c) 2015-2018 Christopher Reichert 2017-2018 Daniel Fithian
LicenseBSD3
MaintainerChristopher Reichert <creichert07@gmail.com>, Daniel Fithian <daniel.m.fithian@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
  let expirationSpec = TimeSpec 5 0 -- five seconds
  th <- initThrottler (defaultThrottleSettings expirationSpec) (const $ Right 1)
  let appl = throttle th $  _ f -> f $
        responseLBS ok200 [] "ok"
  Warp.run 3000 app
Synopsis

Documentation

data ThrottleSettings Source #

Throttle settings for controlling token bucket algorithm and cache expiration.

Constructors

ThrottleSettings 

Fields

data Throttle a Source #

A throttle for a hashable key type. Initialize using initThrottler with defaultThrottleSettings.

Constructors

Throttle 

Fields

defaultThrottleSettings :: TimeSpec -> ThrottleSettings Source #

Default throttle settings.

initCustomThrottler :: ThrottleSettings -> (Request -> Either Response a) -> IO (Throttle a) Source #

Initialize a throttle using settings and a way to extract the key from the request.

throttle :: (Eq a, Hashable a) => Throttle a -> Application -> Application Source #

Run the throttling middleware given a throttle that has been initialized.