HttpBucket class
A rate limit bucket tracking requests.
Every response from Discord's API contains headers to handle rate limiting. This class keeps track of these headers in a single rate limit bucket (identified by the xRateLimitBucket header) and allows the client to anticipate rate limits.
Every HttpHandler stores a map of HttpRoute.rateLimitId to HttpBucket and implicitly checks each request before sending it, waiting if a rate limit would be exceeded.
External references:
- Discord API Reference: https://discord.com/developers/docs/topics/rate-limits#rate-limits
Constructors
- HttpBucket(HttpHandler handler, {required String id, required int remaining, required DateTime resetAt})
- Create a new HttpBucket.
Properties
- handler → HttpHandler
-
The HttpHandler to which this bucket belongs.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
The id of this bucket.
final
- inflightRequests → int
-
The number of in-flight requests in this bucket.
no setter
- remaining → int
-
The remaining number of requests that can be made in this reset period.
no setter
- resetAfter → Duration
-
The duration after which this bucket resets.
no setter
- resetAt → DateTime
-
The time at which this bucket resets.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addInflightRequest(
HttpRequest request) → void -
Add
request
to this bucket's in-flight requests. -
contains(
BaseResponse response) → bool -
Return whether the
response
's xRateLimitBucket header matches this bucket's. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeInflightRequest(
HttpRequest request) → void -
Remove
request
from this bucket's in-flight requests. -
toString(
) → String -
A string representation of this object.
inherited
-
updateWith(
BaseResponse response) → void -
Update this bucket with the values from
response
.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromResponse(
HttpHandler handler, BaseResponse response) → HttpBucket? - Create a HttpBucket from a response from the API.
Constants
- xRateLimitBucket → const String
- The name of the header containing the rate limit bucket id.
- xRateLimitLimit → const String
- The name of the header containing the rate limit per reset.
- xRateLimitRemaining → const String
- The name of the header containing the remaining request count in the current reset.
- xRateLimitReset → const String
- The name of the header containing the time at which the rate limit for this bucket will reset.
- xRateLimitResetAfter → const String
- The name of the header containing the amount of time until the rate limit resets, in seconds.