Rate Limiting configuration - policy validation
See original GitHub issueBackground and Motivation
The ASP.NET Core rate limiting middleware is great, but “limited” in terms of policy validation. Let’s start with some code that you can write today in .NET 7:
builder.Services.AddRateLimiter(options =>
{
options.AddFixedWindowLimiter("customPolicy", opt =>
{
opt.PermitLimit = 4;
opt.Window = TimeSpan.FromSeconds(12);
opt.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
opt.QueueLimit = 2;
});
// ...
});
There is no way to validate that customPolicy
actually exists. This is useful when configuring multiple routes from configuration such as is the case for YARP. See https://github.com/microsoft/reverse-proxy/pull/1967
Proposed API
It would be preferred to something similar to IAuthorizationPolicyProvider
implemented via DefaultAuthorizationPolicyProvider
and ICorsPolicyProvider
implemented via DefaultCorsPolicyProvider
namespace Microsoft.AspNetCore.RateLimiting;
- internal struct DefaultKeyType
+ public struct DefaultKeyType
{
// omitted ...
}
+
+ public interface IRateLimiterPolicyProvider
+ {
+ ValueTask<IRateLimiterPolicy<DefaultKeyType>?> GetDefaultPolicyAsync();
+ ValueTask<IRateLimiterPolicy<DefaultKeyType>?> GetPolicyAsync(string policyName);
+ }
+
+ public class DefaultRateLimiterPolicyProvider : IRateLimiterPolicyProvider
+ {
+ private readonly RateLimiterOptions _options;
+
+ public DefaultRateLimiterPolicyProvider(IOptions<RateLimiterOptions> options)
+ {
+
+ }
+
+ public ValueTask<IRateLimiterPolicy<DefaultKeyType>?> GetPolicyAsync(string policyName)
+ {
+ options.PolicyMap[policyName] ?? options.UnactivatedPolicyMap[policyName];
+ }
+ }
RateLimiterOptions.PolicyMap
is internal hence this feature cannot be added in another library or the final application.
Usage Examples
Alternative Designs
None
Risks
None
Issue Analytics
- State:
- Created 9 months ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Rate Limiting Policy
When you configure the Rate Limiting policy, you can specify any number of pairs of quota (number of requests) and time window (time...
Read more >Rate Limiting Policy | Zuplo Docs
Rate -limiting allows you to set a maximum rate of requests for your API gateway. This is useful to enforce rate limits agreed...
Read more >7 - Configure Rate Limiting, Header Validation and Routing ...
Learn how to configure API Rate Limiting, Header Validation and Resource Based Routing policies in Oracle API Platform Cloud Service.
Read more >Rate limiting
Rate limiting is performed by taking the incoming request and identifying the parts of the request that makes it unique to a client....
Read more >Rate Limit Policy
To ensure the quality of Auth0's services, the Auth0 APIs are subject to rate limiting. Depending on the API endpoint, the request limit...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This proposal will be discussed by our team in an upcoming API review meeting, after which we’ll provide feedback/suggestions.
Once a proposal gets to the
api-approved
state, we’ll be ready to take a PR to implement the change.@adityamandaleeka this is done