Copyright | (c) 2015 Christopher Reichert |
---|---|
License | BSD3 |
Maintainer | Christopher Reichert <creichert07@gmail.com> |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
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
- throttle :: ThrottleSettings -> WaiThrottle -> Application -> Application
- data WaiThrottle
- initThrottler :: IO WaiThrottle
- data ThrottleSettings = ThrottleSettings {
- isThrottled :: !(Request -> IO Bool)
- onThrottled :: !(Word64 -> Response)
- throttleRate :: !Integer
- throttlePeriod :: !Integer
- throttleBurst :: !Integer
- defaultThrottleSettings :: ThrottleSettings
Documentation
Wai Request Throttling Middleware
throttle :: ThrottleSettings -> WaiThrottle -> Application -> Application Source
WAI Request Throttling Middleware.
Uses a Request
s remoteHost
function to resolve the
remote IP address.
Wai Throttle middleware state.
Essentially, a TVar with a HashMap for indexing remote IP address
data WaiThrottle Source
Throttle settings and configuration
data ThrottleSettings Source
Settings which control various behaviors in the middleware.
ThrottleSettings | |
|
defaultThrottleSettings :: ThrottleSettings Source
Default settings to throttle requests.