HttpResponseHeadersExtensions Class
- Namespace
- Kampute.HttpClient
- Assembly
- Kampute.HttpClient.dll
Definition
Provides extension methods that read the retry time a response suggests from its headers.
public static class HttpResponseHeadersExtensions- Inheritance
- object
- HttpResponseHeadersExtensions
Methods
TryExtractRateLimitResetTime(this HttpResponseHeaders, out DateTimeOffset?)
Reads the time when a rate limit resets from the
Retry-After header or a rate limit reset header.public static bool TryExtractRateLimitResetTime(this HttpResponseHeaders headers, out DateTimeOffset? resetTime)Parameters
headersHttpResponseHeaders- The response headers.
resetTimeDateTimeOffset?- When this method returns, the time the headers suggest, or
nullif they suggest none.
Returns
Remarks
TryExtractRetryAfterTime(this HttpResponseHeaders, out DateTimeOffset?)
Reads the retry time from the
Retry-After header.public static bool TryExtractRetryAfterTime(this HttpResponseHeaders headers, out DateTimeOffset? retryAfterTime)Parameters
headersHttpResponseHeaders- The response headers.
retryAfterTimeDateTimeOffset?- When this method returns, the time the header suggests, or
nullif it has none. A number of seconds is converted to a time from now.

The method first looks for a
Retry-Afterheader. If there is none, it reads the first rate limit reset header it finds amongratelimit-reset,rate-limit-reset,x-ratelimit-resetandx-rate-limit-reset.A rate limit reset value from 0 to 86400 is read as a number of seconds from now. A larger value, up to 253402300799 (the Unix time of DateTimeOffset.MaxValue), is read as a Unix time in seconds. Any other value, such as a negative number or a time in milliseconds, is treated as if the header were missing.