From ef993eced35d7cd3ca46e93e69244a50b06db53d Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 14 Aug 2019 15:09:48 -0400 Subject: [PATCH] denyRequest skeleton --- lib/src/rate_limiter.dart | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/src/rate_limiter.dart b/lib/src/rate_limiter.dart index 20b58598..67897da6 100644 --- a/lib/src/rate_limiter.dart +++ b/lib/src/rate_limiter.dart @@ -1,5 +1,7 @@ import 'dart:async'; import 'package:angel_framework/angel_framework.dart'; +import 'package:angel_security/angel_security.dart'; +import 'rate_limiting_window.dart'; /// A base class that facilitates rate limiting API's or endpoints, /// typically to prevent spam and abuse. @@ -16,4 +18,21 @@ abstract class RateLimiter { final Duration window; RateLimiter(this.maxRequestsPerWindow, this.window); + + /// Computes the current window in which the user is acting. + /// + /// For example, if your API was limited to 1000 requests/hour, + /// then you would return a window containing the current hour, + /// and the number of requests the user has sent in the past hour. + FutureOr> getCurrentWindow( + RequestContext req, ResponseContext res); + + /// Updates the underlying store with information about the + /// [newWindow] that the user is operating in. + FutureOr updateCurrentWindow(RequestContext req, ResponseContext res, + RateLimitingWindow newWindow); + + FutureOr denyRequest(RequestContext req, ResponseContext res) { + + } }