Table of Contents

Class RateLimitHeaderParser

Namespace
RateLimitHeaders.Parsing
Assembly
RateLimitHeaders.dll

Parses IETF RateLimit headers (draft-ietf-httpapi-ratelimit-headers-10) from HTTP responses.

public static class RateLimitHeaderParser
Inheritance
RateLimitHeaderParser
Inherited Members

Remarks

This parser supports the IETF standard format:

  • RateLimit: "policy";r=remaining;t=reset_seconds
  • RateLimit-Policy: "policy";q=quota;w=window_seconds

Multiple comma-separated policies are supported per the spec:

RateLimit: "burst";r=50;t=30,"daily";r=900;t=43200
When multiple policies are present, policy names are matched between headers and the most restrictive one (lowest remaining percentage) is returned.

Per the specification, malformed headers are silently ignored (never throws).

Fields

RateLimitHeaderName

The standard RateLimit header name.

public const string RateLimitHeaderName = "RateLimit"

Field Value

string

RateLimitPolicyHeaderName

The standard RateLimit-Policy header name.

public const string RateLimitPolicyHeaderName = "RateLimit-Policy"

Field Value

string

Methods

Parse(HttpResponseHeaders)

Parses RateLimit headers from HTTP response headers.

public static RateLimitInfo Parse(HttpResponseHeaders headers)

Parameters

headers HttpResponseHeaders

The HTTP response headers to parse.

Returns

RateLimitInfo

A RateLimitInfo with parsed values, or an invalid instance if parsing fails.

Parse(HttpResponseMessage)

Parses RateLimit headers from an HTTP response.

public static RateLimitInfo Parse(HttpResponseMessage response)

Parameters

response HttpResponseMessage

The HTTP response to parse headers from.

Returns

RateLimitInfo

A RateLimitInfo with parsed values, or an invalid instance if parsing fails.

Parse(string?, string?)

Parses RateLimit headers from raw header values (for testing or custom scenarios).

public static RateLimitInfo Parse(string? rateLimitHeaderValue, string? rateLimitPolicyHeaderValue)

Parameters

rateLimitHeaderValue string

The value of the RateLimit header, or null if not present.

rateLimitPolicyHeaderValue string

The value of the RateLimit-Policy header, or null if not present.

Returns

RateLimitInfo

A RateLimitInfo with parsed values, or an invalid instance if parsing fails.

TryParse(HttpResponseHeaders, out RateLimitInfo)

Attempts to parse RateLimit headers from HTTP response headers.

public static bool TryParse(HttpResponseHeaders headers, out RateLimitInfo rateLimitInfo)

Parameters

headers HttpResponseHeaders

The HTTP response headers to parse.

rateLimitInfo RateLimitInfo

When successful, contains the parsed rate limit information.

Returns

bool

true if at least one header was successfully parsed; otherwise, false.

TryParse(HttpResponseMessage, out RateLimitInfo)

Attempts to parse RateLimit headers from an HTTP response.

public static bool TryParse(HttpResponseMessage response, out RateLimitInfo rateLimitInfo)

Parameters

response HttpResponseMessage

The HTTP response to parse headers from.

rateLimitInfo RateLimitInfo

When successful, contains the parsed rate limit information.

Returns

bool

true if at least one header was successfully parsed; otherwise, false.