wai-rate-limit 0.2.0.0 → 0.3.0.0
raw patch · 3 files changed
+22/−11 lines, 3 filesdep +time-unitsPVP ok
version bump matches the API change (PVP)
Dependencies added: time-units
API changes (from Hackage documentation)
- Network.Wai.RateLimit.Strategy: fixedWindow :: Backend key -> Integer -> Integer -> (Request -> IO key) -> Strategy
+ Network.Wai.RateLimit.Strategy: fixedWindow :: Backend key -> Second -> Integer -> (Request -> IO key) -> Strategy
- Network.Wai.RateLimit.Strategy: slidingWindow :: Backend key -> Integer -> Integer -> (Request -> IO key) -> Strategy
+ Network.Wai.RateLimit.Strategy: slidingWindow :: Backend key -> Second -> Integer -> (Request -> IO key) -> Strategy
Files
- CHANGELOG.md +4/−0
- src/Network/Wai/RateLimit/Strategy.hs +16/−10
- wai-rate-limit.cabal +2/−1
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog for `wai-rate-limit` +## 0.3++- Use the `Second` type from `Data.Time.Units` to more accurately represent the expected arguments for the rate-limiting strategies.+ ## 0.2 - Change how errors are handled by `Backend`s to use exceptions
src/Network/Wai/RateLimit/Strategy.hs view
@@ -5,6 +5,7 @@ -- file in the root directory of this source tree. -- -------------------------------------------------------------------------------- +-- | Exports functions which implement rate-limiting strategies. module Network.Wai.RateLimit.Strategy ( Strategy(..), fixedWindow,@@ -15,6 +16,8 @@ import Control.Monad +import Data.Time.Units+ import Network.Wai import Network.Wai.RateLimit.Backend @@ -28,14 +31,17 @@ strategyOnRequest :: Request -> IO Bool } --- | 'windowStrategy'+-- | `windowStrategy` implements a general window-based rate limiting strategy. windowStrategy- :: Backend key- -> Integer- -> Integer- -> (Request -> IO key)- -> (Integer -> Bool)- -> Request+ :: Backend key -- ^ The storage backend to use.+ -> Second -- ^ The number of seconds after which recorded usage expires.+ -> Integer -- ^ How much capacity each key should have.+ -> (Request -> IO key) -- ^ A function which computes a key for the+ -- request.+ -> (Integer -> Bool) -- ^ A predicate which determines whether the expiry+ -- timer should be reset.+ -> Request -- ^ The request to apply the stragey to, used for deriving+ -- the key. -> IO Bool windowStrategy MkBackend{..} seconds capacity getKey cond req = do -- get a key to identify the usage bucket for the request: this is@@ -50,7 +56,7 @@ -- acceptable limit and, if so, add to the expiry timer if used <= capacity then do- when (cond used) $ void $ backendExpireIn key seconds+ when (cond used) $ void $ backendExpireIn key (toInteger seconds) pure True else pure False @@ -58,7 +64,7 @@ -- of requests made by a client to @limit@ within a window of @seconds@. fixedWindow :: Backend key- -> Integer+ -> Second -> Integer -> (Request -> IO key) -> Strategy@@ -76,7 +82,7 @@ -- been exceeded. slidingWindow :: Backend key- -> Integer+ -> Second -> Integer -> (Request -> IO key) -> Strategy
wai-rate-limit.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: wai-rate-limit-version: 0.2.0.0+version: 0.3.0.0 synopsis: Rate limiting as WAI middleware description: A Haskell library which implements rate limiting as WAI middleware category: Security@@ -41,5 +41,6 @@ build-depends: base >=4.8 && <5 , http-types <1+ , time-units ==1.* , wai >=3.0 && <4 default-language: Haskell2010