-
Notifications
You must be signed in to change notification settings - Fork 10.3k
RateLimitingMiddleware updates #43053
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
Changes from all commits
aa99531
835fca4
9313b49
99e4d65
279b8b7
5a6c107
df7ffba
9c52cd9
c3ee131
1b535f1
e8339d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.RateLimiting; | ||
|
||
/// <summary> | ||
/// Metadata that disables request rate limiting on an endpoint. | ||
wtgodbe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
/// <remarks> | ||
/// Completely disables the rate limiting middleware from applying to this endpoint. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||
public sealed class DisableRateLimitingAttribute : Attribute | ||
{ | ||
internal static DisableRateLimitingAttribute Instance { get; } = new DisableRateLimitingAttribute(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.RateLimiting; | ||
|
||
/// <summary> | ||
/// Metadata that provides endpoint-specific request rate limiting. | ||
wtgodbe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
/// <remarks> | ||
/// Replaces any policies currently applied to the endpoint. | ||
/// The global limiter will still run on endpoints with this attribute applied. | ||
/// </remarks> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||
public sealed class EnableRateLimitingAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="EnableRateLimitingAttribute"/> using the specified policy. | ||
/// </summary> | ||
/// <param name="policyName">The name of the policy which needs to be applied.</param> | ||
public EnableRateLimitingAttribute(string policyName) | ||
{ | ||
ArgumentNullException.ThrowIfNull(policyName); | ||
|
||
PolicyName = policyName; | ||
} | ||
|
||
internal EnableRateLimitingAttribute(DefaultRateLimiterPolicy policy) | ||
{ | ||
Policy = policy; | ||
} | ||
|
||
/// <summary> | ||
/// The name of the policy which needs to be applied. | ||
/// </summary> | ||
public string? PolicyName { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels super weird, from a consumer perspective there is no way this can be null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure it can. Add an inline policy using the |
||
|
||
/// <summary> | ||
/// The policy which needs to be applied, if present. | ||
/// </summary> | ||
internal DefaultRateLimiterPolicy? Policy { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is sad, someone who wants to write their own rate limiting middleware (maybe they disagree with some design decision, like want to run global and endpoint specific limits no matter if one fails) with our options and attributes won't be able to access this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also the case with named polices. It's not like the policy maps on RateLimiterOptions are public. If we want to design for people replacing the middleware but not the options/metadata, we have to consider that way up front and not now. Maybe we could do it in a different major release if it's important. I'm not convinced yet. |
||
} |
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.