Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for AspNetCore 7 rate limiting #1967

Merged
merged 10 commits into from
Jan 13, 2023

Conversation

mburumaxwell
Copy link
Contributor

Add support for Rate Limiting available from AspNetCore 7.0.

Caveats:

  • The repo/libraries support both net6 and net7 using #if NET7_0_OR_GREATER which can potentially be a problem for maintenance.
  • There is no means to validate the policy actually exists without the prescence of an interface/class similar to IAuthorizationPolicyProvider or ICorsPolicyProvider. The RateLimitingMiddleware uses RateLimiterOptions.PolicyMap but it is internal. Hopefully something will be available in AspNetCore 8 to allow validation. A TODO exists in the validation just tracking and as a reminder.
  • Not possible to use default similar to AuthorizationPolicy and CorsPolicy because the EnableRateLimitingAttribute requires a policyName. Default policy would have to be configured in the serivces setup:
    services.AddRateLimiter(options => { /* conf stuff here */ });

Fixes: #1776

@Tratcher Tratcher self-assigned this Dec 19, 2022
@Tratcher Tratcher added this to the YARP 2.0.0 milestone Dec 19, 2022
@Tratcher
Copy link
Member

  • There is no means to validate the policy actually exists without the prescence of an interface/class similar to IAuthorizationPolicyProvider or ICorsPolicyProvider. The RateLimitingMiddleware uses RateLimiterOptions.PolicyMap but it is internal. Hopefully something will be available in AspNetCore 8 to allow validation. A TODO exists in the validation just tracking and as a reminder.

Is there an issue tracking that in AspNetCore?

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice

docs/docfx/articles/rate-limiting.md Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
src/ReverseProxy/Configuration/ConfigValidator.cs Outdated Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
Copy link
Member

@MihaZupan MihaZupan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
docs/docfx/articles/rate-limiting.md Outdated Show resolved Hide resolved
src/ReverseProxy/Configuration/ConfigValidator.cs Outdated Show resolved Hide resolved
src/ReverseProxy/Configuration/RouteConfig.cs Outdated Show resolved Hide resolved
@Tratcher
Copy link
Member

@mburumaxwell I pushed some fixes to your branch so we can get this into the upcoming preview release. Thanks for helping out.

@mburumaxwell
Copy link
Contributor Author

@mburumaxwell I pushed some fixes to your branch so we can get this into the upcoming preview release. Thanks for helping out.

Okay. Looking forward. Should the same workflow be used for output caching? (Also introduced in .NET7)

@MihaZupan MihaZupan merged commit 7fcbcf4 into microsoft:main Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set Rate limiter schema for Routes
4 participants