platform/lib/src/rate_limiter.dart

20 lines
703 B
Dart
Raw Normal View History

2019-08-14 18:49:14 +00:00
import 'dart:async';
2019-08-14 18:46:53 +00:00
import 'package:angel_framework/angel_framework.dart';
/// A base class that facilitates rate limiting API's or endpoints,
/// typically to prevent spam and abuse.
2019-08-14 18:49:14 +00:00
///
/// The rate limiter operates under the assumption that a [User] object
/// can be computed from each request, as well as information about
/// the current rate-limiting window.
abstract class RateLimiter<User> {
2019-08-14 18:46:53 +00:00
/// The maximum number of requests allowed within the given [window].
final int maxRequestsPerWindow;
/// The amount of time, during which, a user is not allowed to send
/// more than [maxRequestsPerWindow].
final Duration window;
RateLimiter(this.maxRequestsPerWindow, this.window);
}