-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47e2722
commit 481bc70
Showing
12 changed files
with
109 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/AspNetCoreRateLimit/CounterKeyBuilders/ClientCounterKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace AspNetCoreRateLimit | ||
{ | ||
public class ClientCounterKeyBuilder : ICounterKeyBuilder | ||
{ | ||
private readonly ClientRateLimitOptions _options; | ||
|
||
public ClientCounterKeyBuilder(ClientRateLimitOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
public string Build(ClientRequestIdentity requestIdentity, RateLimitRule rule) | ||
{ | ||
return $"{_options.RateLimitCounterPrefix}_{requestIdentity.ClientId}_{rule.Period}"; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/AspNetCoreRateLimit/CounterKeyBuilders/EndpointCounterKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace AspNetCoreRateLimit | ||
{ | ||
public class EndpointCounterKeyBuilder : ICounterKeyBuilder | ||
{ | ||
public string Build(ClientRequestIdentity requestIdentity, RateLimitRule rule) | ||
{ | ||
// This will allow to rate limit /api/values/1 and api/values/2 under same counter | ||
return $"_{requestIdentity.HttpVerb}_{requestIdentity.Path}_{rule.Endpoint}"; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/AspNetCoreRateLimit/CounterKeyBuilders/ICounterKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AspNetCoreRateLimit | ||
{ | ||
public interface ICounterKeyBuilder | ||
{ | ||
string Build(ClientRequestIdentity requestIdentity, RateLimitRule rule); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/AspNetCoreRateLimit/CounterKeyBuilders/IpCounterKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace AspNetCoreRateLimit | ||
{ | ||
public class IpCounterKeyBuilder : ICounterKeyBuilder | ||
{ | ||
private readonly IpRateLimitOptions _options; | ||
|
||
public IpCounterKeyBuilder(IpRateLimitOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
public string Build(ClientRequestIdentity requestIdentity, RateLimitRule rule) | ||
{ | ||
return $"{_options.RateLimitCounterPrefix}_{requestIdentity.ClientIp}_{rule.Period}"; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/AspNetCoreRateLimit/CounterKeyBuilders/PathCounterKeyBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AspNetCoreRateLimit | ||
{ | ||
public class PathCounterKeyBuilder : ICounterKeyBuilder | ||
{ | ||
public string Build(ClientRequestIdentity requestIdentity, RateLimitRule rule) | ||
{ | ||
return $"_{requestIdentity.HttpVerb}_{requestIdentity.Path}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters