pub struct Headers {
pub limit: usize,
pub remaining: usize,
pub reset: ResetTime,
pub window: Option<Duration>,
pub vendor: Vendor,
pub candidates: VendorMask,
}Expand description
HTTP rate limits as parsed from header values
Fields§
§limit: usizeThe maximum number of requests allowed in the time window
remaining: usizeThe number of requests remaining in the time window
reset: ResetTimeThe time at which the rate limit will be reset
window: Option<Duration>The time window until the rate limit is lifted. It is marked optional, because it might not be provided, in which case it needs to be inferred from the context
vendor: VendorPredicted vendor based on rate limit header
candidates: VendorMaskAll candidates that matched the headers
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn new(headers: &HeaderMap) -> Result<Self, Error>
pub fn new(headers: &HeaderMap) -> Result<Self, Error>
Extracts rate limits from an iterator of HTTP headers.
Different vendors (e.g. GitHub, Vimeo, Twitter) use different header names. This function attempts to identify the vendor based on the presence of known headers.
There are many websites abusing or reusing rate limit headers with their own definition of what the values mean. This library tries to be pessimistic and only attempts to parse the rate limit headers if it trusts the website to follow one of the supported variants.
Some vendors might use the same header names but different value formats. In this case, the library will try to parse the headers using the different variants until one succeeds.
When parsing headers, casing is significant.
For example, GitHub uses “x-ratelimit-remaining” while
Reddit uses “X-Ratelimit-Remaining.”
This is also why we use an iterator of header key-value pairs instead of
a case-insensitive map like http::HeaderMap.
§Errors
Returns an error if the headers do not contain a known rate limit format, or if the header values cannot be parsed.