ThrottleMiddleware class final
throttle:60,1 (max attempts, decay minutes) or throttle:api
(named limiter). Adds X-RateLimit-Limit/X-RateLimit-Remaining to
responses and answers 429 with Retry-After when exceeded.
- Implemented types
Constructors
-
ThrottleMiddleware({int maxAttempts = 60, Duration decay = const Duration(minutes: 1), String? limiterName, String prefix = '', RateLimiter? limiter, FutureOr<
Object?> userKeyResolver(Request request)?}) -
const
-
ThrottleMiddleware.fromParams(List<
String> params, {RateLimiter? limiter, FutureOr<Object?> userKeyResolver(Request request)?}) -
Parses alias parameters (
['60', '1']or['api']).factory
Properties
- decay → Duration
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- limiter → RateLimiter?
-
final
- limiterName → String?
-
final
- maxAttempts → int
-
final
- prefix → String
-
Key prefix separating independent throttles sharing a resolver.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
userKeyResolver
→ FutureOr<
Object?> Function(Request request)? -
Returns the authenticated user's id (or
nullfor guests) so limits follow the user instead of the IP.final
Methods
-
handle(
Request request, Next next) → Future< Response> -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited