sendWindowInformation method

FutureOr<void> sendWindowInformation(
  1. RequestContext req,
  2. ResponseContext res,
  3. RateLimitingWindow<User> window
)

Alerts the user of information pertinent to the current window.

The default implementation is to send the following headers, akin to Github's v4 Graph API:

  • X-RateLimit-Limit: The maximum number of points consumed per window.
  • X-RateLimit-Remaining: The remaining number of points that may be consumed before the rate limit is reached for the current window.
  • X-RateLimit-Reset: The Unix timestamp, at which the window will reset.

Implementation

FutureOr<void> sendWindowInformation(RequestContext req, ResponseContext res,
    RateLimitingWindow<User> window) {
  res.headers.addAll({
    'x-ratelimit-limit': window.pointLimit.toString(),
    'x-ratelimit-remaining': window.remainingPoints.toString(),
    'x-ratelimit-reset':
        (window.resetTime!.millisecondsSinceEpoch ~/ 1000).toString(),
  });
}