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

Safe HaskellNone
LanguageHaskell2010

Network.Wai.Middleware.Throttle.Internal

Synopsis

Documentation

data Throttle a Source #

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

Constructors

Throttle 

Fields

data ThrottleSettings Source #

Throttle settings for controlling token bucket algorithm and cache expiration.

Constructors

ThrottleSettings 

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.

retrieveCache :: (Eq a, Hashable a) => Throttle a -> TimeSpec -> a -> STM (CacheResult TokenBucket) Source #

Internal use only. Retrieve a token bucket from the cache.

processCacheResult :: (Eq a, Hashable a) => Throttle a -> a -> CacheResult TokenBucket -> IO TokenBucket Source #

Internal use only. Create a token bucket if it wasn't in the cache.

retrieveOrInitializeBucket :: (Eq a, Hashable a) => Throttle a -> a -> IO TokenBucket Source #

Internal use only. Retrieve or initialize a token bucket depending on if it was found in the cache.

throttleRequest :: (Eq a, Hashable a) => Throttle a -> a -> IO Word64 Source #

Internal use only. Throttle a request by the throttle key.

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

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