Table of Contents

Class RateLimiterOptionsExtensions

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

Configures ASP.NET Core rate-limit rejections to use the canonical Trellis Problem Details response.

public static class RateLimiterOptionsExtensions
Inheritance
RateLimiterOptionsExtensions
Inherited Members

Methods

UseTrellisRejectionHandler(RateLimiterOptions, Func<OnRejectedContext, CancellationToken, ValueTask>?)

Installs the Trellis rejection handler on options.

public static RateLimiterOptions UseTrellisRejectionHandler(this RateLimiterOptions options, Func<OnRejectedContext, CancellationToken, ValueTask>? observer = null)

Parameters

options RateLimiterOptions

The ASP.NET Core rate-limiter options.

observer Func<OnRejectedContext, CancellationToken, ValueTask>

An optional logging or metrics observer invoked before Trellis writes the response. The observer may inspect the rejection context but must not mutate or start its HTTP response, including from an OnStarting callback.

Returns

RateLimiterOptions

The same options instance for chaining.

Remarks

The handler converts RetryAfter lease metadata into RetryAdvice and writes Error.RateLimited through the normal Trellis response pipeline. Rejections therefore use the configured TrellisAspOptions mapping and emit Retry-After when the limiter supplies the metadata.

This method owns OnRejected and does not compose with an existing handler because that handler may already write a response. Pass logging or metrics work through observer instead. Applications that need a different writer should not install this adapter.

Register endpoint policies by name without a policy-level OnRejected callback. ASP.NET Core gives policy-level callbacks precedence over the options handler; inline RequireRateLimiting(policy) bypasses it even when the policy callback is null. These endpoint configurations cannot be rendered by this adapter.

Exceptions

ArgumentNullException

options is null.

InvalidOperationException

OnRejected already has a handler, or observer mutates or starts the response.