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 Nullable<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 Nullable<DateTimeOffset> resetTime)

Parameters

headers HttpResponseHeaders
The response headers.
resetTime Nullable<DateTimeOffset>
When this method returns, the time the headers suggest, or null if they suggest none.

Returns

bool
true if a header has a valid value; otherwise, false.

Remarks

The method first looks for a Retry-After header. If there is none, it reads the first rate limit reset header it finds among ratelimit-reset, rate-limit-reset, x-ratelimit-reset and x-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.

TryExtractRetryAfterTime(this HttpResponseHeaders, out Nullable<DateTimeOffset>)

Reads the retry time from the Retry-After header.
public static bool TryExtractRetryAfterTime(this HttpResponseHeaders headers, out Nullable<DateTimeOffset> retryAfterTime)

Parameters

headers HttpResponseHeaders
The response headers.
retryAfterTime Nullable<DateTimeOffset>
When this method returns, the time the header suggests, or null if it has none. A number of seconds is converted to a time from now.

Returns

bool
true if the header has a valid date or number of seconds; otherwise, false.