denyRequest skeleton
This commit is contained in:
parent
c69b8e1405
commit
ef993eced3
1 changed files with 19 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
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,
|
/// A base class that facilitates rate limiting API's or endpoints,
|
||||||
/// typically to prevent spam and abuse.
|
/// typically to prevent spam and abuse.
|
||||||
|
@ -16,4 +18,21 @@ abstract class RateLimiter<User> {
|
||||||
final Duration window;
|
final Duration window;
|
||||||
|
|
||||||
RateLimiter(this.maxRequestsPerWindow, this.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<RateLimitingWindow<User>> getCurrentWindow(
|
||||||
|
RequestContext req, ResponseContext res);
|
||||||
|
|
||||||
|
/// Updates the underlying store with information about the
|
||||||
|
/// [newWindow] that the user is operating in.
|
||||||
|
FutureOr<void> updateCurrentWindow(RequestContext req, ResponseContext res,
|
||||||
|
RateLimitingWindow<User> newWindow);
|
||||||
|
|
||||||
|
FutureOr<Object> denyRequest(RequestContext req, ResponseContext res) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue