From 0f6011d6934e14419205c816f2a40325b3ff4e4f Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 14 Aug 2019 15:19:37 -0400 Subject: [PATCH] Add endpoint cost --- lib/src/rate_limiter.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/src/rate_limiter.dart b/lib/src/rate_limiter.dart index 3c4bc450..a14af9f9 100644 --- a/lib/src/rate_limiter.dart +++ b/lib/src/rate_limiter.dart @@ -30,8 +30,19 @@ abstract class RateLimiter { /// Updates the underlying store with information about the new /// [window] that the user is operating in. - FutureOr updateCurrentWindow(RequestContext req, ResponseContext res, - RateLimitingWindow window); + FutureOr updateCurrentWindow( + RequestContext req, ResponseContext res, RateLimitingWindow window); + + /// Computes the amount of points that a given request will cost. This amount + /// is then added to the amount of points that the user has already consumed + /// in the current [window]. + /// + /// The default behavior is to return `1`, which signifies that all requests + /// carry the same weight. + FutureOr getEndpointCost(RequestContext req, ResponseContext res, + RateLimitingWindow window) { + return Future.value(1); + } FutureOr denyRequest(RequestContext req, ResponseContext res, RateLimitingWindow window) {}