dotnet / dotnet/aspnetcore

Support custom `PartitionedRateLimiter<HttpContext>` per endpoint

Open
#63,505 0 comments 0 reactions 0 assignees View on GitHub
area-middleware feature-rate-limit
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

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

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

The closest thing that `AddPolicy` accepts is callback that needs to return `RateLimitPartition` 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> factory)`
or
`public RateLimiterOptions AddPolicy(string policyName, PartitionedRateLimiter rateLimiter)`

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.