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

Copyright(c) 2015-2017 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 :: RequestHashable a => ThrottleSettings -> CustomWaiThrottle a -> 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

type WaiThrottle = CustomWaiThrottle Address Source #

A synonym for an IP address throttle

data CustomWaiThrottle a Source #

A throttle for a type implementing RequestHashable

initThrottler :: IO WaiThrottle Source #

Initialize an IP address throttler

initCustomThrottler :: IO (CustomWaiThrottle a) Source #

Initialize a "custom" throttler that implements the RequestHashable class

Throttle settings and configuration

data ThrottleSettings Source #

Settings which control various behaviors in the middleware.

Constructors

ThrottleSettings 

Fields

defaultThrottleSettings :: ThrottleSettings Source #

Default settings to throttle requests.

class (Eq a, Ord a, Hashable a) => RequestHashable a where Source #

A class extracting a hashable key from a Request to store in an in-memory map

Minimal complete definition

requestToKey

Methods

requestToKey :: (Functor m, Monad m) => Request -> ExceptT Text m a Source #