Table of Contents

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

options RateLimitAwareOptions

The 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

options RateLimitAwareOptions

The handler options.

logger ILogger

The 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

request HttpRequestMessage

The HTTP request message to send to the server.

cancellationToken CancellationToken

A cancellation token to cancel operation.

Returns

Task<HttpResponseMessage>

The task object representing the asynchronous operation.

Exceptions

ArgumentNullException

The request was null.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.