pub struct Headers {
pub limit: usize,
pub remaining: usize,
pub reset: ResetTime,
pub window: Option<Duration>,
pub vendor: Vendor,
}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 optional, because it might not be given, in which case it needs to be inferred from the environment
vendor: VendorPredicted vendor based on rate limit header
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn new<T: Into<CaseSensitiveHeaderMap>>(headers: T) -> Result<Self, Error>
pub fn new<T: Into<CaseSensitiveHeaderMap>>(headers: T) -> Result<Self, Error>
Extracts rate limits from 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.
§Errors
Returns an error if the headers do not contain a known rate limit format, or if the header values cannot be parsed.