Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametrize HasRateLimitStrategy by key #10

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions servant-rate-limit/src/Servant/RateLimit/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Servant.Server.Internal.DelayedIO

-- | A class of types which are type-level descriptions of rate-limiting
-- strategies.
class HasRateLimitStrategy (ctx :: [Type]) strategy where
class HasRateLimitStrategy (ctx :: [Type]) strategy key where
-- | `strategyValue` @context backend getKey@ is a function which, given a
-- @backend@ and a function @getKey@ used to compute the key using which
-- the client should be identified, returns a rate-limiting `Strategy`.
Expand All @@ -50,7 +50,7 @@ class HasRateLimitStrategy (ctx :: [Type]) strategy where

instance
(KnownDuration dur, KnownNat capacity, Units.TimeUnit (DurationUnit dur))
=> HasRateLimitStrategy ctx (FixedWindow dur capacity)
=> HasRateLimitStrategy ctx (FixedWindow dur capacity) key
where

strategyValue _ backend getKey = fixedWindow
Expand All @@ -61,7 +61,7 @@ instance

instance
(KnownDuration dur, KnownNat capacity, Units.TimeUnit (DurationUnit dur))
=> HasRateLimitStrategy ctx (SlidingWindow dur capacity)
=> HasRateLimitStrategy ctx (SlidingWindow dur capacity) key
where

strategyValue _ backend getKey = slidingWindow
Expand Down Expand Up @@ -94,7 +94,7 @@ instance KnownSymbol prefix => HasRateLimitPolicy ctx (IPAddressPolicy prefix) w
instance
( HasServer api ctx
, HasContextEntry ctx (Backend key)
, HasRateLimitStrategy ctx strategy
, HasRateLimitStrategy ctx strategy key
, HasRateLimitPolicy ctx policy
, key ~ RateLimitPolicyKey ctx policy
) => HasServer (RateLimit strategy policy :> api) ctx
Expand Down