Class RateLimitAwareHandler
- Namespace
- RateLimitHeaders.Http
- Assembly
- RateLimitHeaders.dll
A delegating handler that parses IETF RateLimit headers from HTTP responses and can proactively throttle requests to avoid hitting rate limits.
public sealed class RateLimitAwareHandler : DelegatingHandler, IDisposable
- Inheritance
-
RateLimitAwareHandler
- Implements
- Inherited Members
Remarks
This handler should be registered as transient and used with IHttpClientFactory. Handler instances are pooled for approximately 2 minutes.
The handler parses RateLimit and RateLimit-Policy headers per the
IETF specification (draft-ietf-httpapi-ratelimit-headers-10).
Constructors
RateLimitAwareHandler()
Initializes a new instance of the RateLimitAwareHandler class with default options.
public RateLimitAwareHandler()
RateLimitAwareHandler(RateLimitAwareOptions)
Initializes a new instance of the RateLimitAwareHandler class with the specified options.
public RateLimitAwareHandler(RateLimitAwareOptions options)
Parameters
optionsRateLimitAwareOptionsThe handler options.
RateLimitAwareHandler(RateLimitAwareOptions, ILogger)
Initializes a new instance of the RateLimitAwareHandler class with the specified options and logger.
public RateLimitAwareHandler(RateLimitAwareOptions options, ILogger logger)
Parameters
optionsRateLimitAwareOptionsThe handler options.
loggerILoggerThe logger instance.
Methods
SendAsync(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
The
requestwas null.- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.