Skip to content

Support custom PartitionedRateLimiter<HttpContext> per endpoint #63505

@miroljub1995

Description

@miroljub1995

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Right now custom PartitionedRateLimiter<HttpContext> is supported only as GlobalLimiter and it is not possible to attach custom implementation of PartitionedRateLimiter<HttpContext> to name with AddPolicy.

The closest thing that AddPolicy accepts is callback that needs to return RateLimitPartition<TPartitionKey> which has Factory property that returns RateLimiter and that rate limiter is not HttpContext aware.

Background:
We need to build an internal endpoint that needs to do some concurrency rate limiting based on some HTTP header. It should make priorities based on value from header, not just plain FIFO or LIFO queue like ConcurrencyLimiter does. In order to prioritise acquires, rate limiter needs to know for HttpContext, calculate priority when some Lease is disposed and pick the next from queue to be acquired.

Describe the solution you'd like

On RateLimiterOptions:
public RateLimiterOptions AddPolicy(string policyName, Func<HttpContext, PartitionedRateLimiter<HttpContext>> factory)
or
public RateLimiterOptions AddPolicy(string policyName, PartitionedRateLimiter<HttpContext> rateLimiter)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-rate-limitWork related to use of rate limit primitives

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions