-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from 239573049/feature/rate-limit
Feature/rate limit
- Loading branch information
Showing
22 changed files
with
1,140 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace FastGateway.Core; | ||
|
||
public enum RateLimitType : byte | ||
{ | ||
/// <summary> | ||
/// 并发策略 | ||
/// </summary> | ||
Concurrent = 1, | ||
|
||
/// <summary> | ||
/// 令牌桶 | ||
/// </summary> | ||
TokenBucket = 2, | ||
|
||
/// <summary> | ||
/// 滑动窗口 | ||
/// </summary> | ||
SlidingWindow = 3, | ||
|
||
/// <summary> | ||
/// 固定窗口 | ||
/// </summary> | ||
FixedWindow = 4 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
namespace FastGateway.Domain; | ||
|
||
public sealed class RateLimit | ||
{ | ||
/// <summary> | ||
/// 限流策略名称 | ||
/// </summary> | ||
[Column(IsIdentity = true)] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// 是否启用 | ||
/// </summary> | ||
public bool Enable { get; set; } | ||
|
||
/// <summary> | ||
/// 通用规则列表 | ||
/// </summary> | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<GeneralRules> GeneralRules { get; set; } | ||
|
||
/// <summary> | ||
/// 端点白名单 | ||
/// </summary> | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<string> EndpointWhitelist { get; set; } | ||
|
||
/// <summary> | ||
/// 客户端ID头部 | ||
/// </summary> | ||
public string ClientIdHeader { get; set; } = "X-ClientId"; | ||
|
||
/// <summary> | ||
/// 客户端白名单 | ||
/// </summary> | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<string> ClientWhitelist { get; set; } | ||
|
||
/// <summary> | ||
/// 真实IP头部 | ||
/// </summary> | ||
public string RealIpHeader { get; set; } = "X-Real-IP"; | ||
|
||
/// <summary> | ||
/// IP白名单 | ||
/// </summary> | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<string> IpWhitelist { get; set; } | ||
|
||
/// <summary> | ||
/// HTTP状态码 | ||
/// </summary> | ||
public int HttpStatusCode { get; set; } = 429; | ||
|
||
/// <summary> | ||
/// 超出配额消息 | ||
/// </summary> | ||
public string QuotaExceededMessage { get; set; } | ||
|
||
/// <summary> | ||
/// 错误内容类型 | ||
/// </summary> | ||
public string RateLimitContentType { get; set; } = "text/html"; | ||
|
||
/// <summary> | ||
/// 速率限制计数器前缀 | ||
/// </summary> | ||
public string RateLimitCounterPrefix { get; set; } = "crlc"; | ||
|
||
/// <summary> | ||
/// 启用端点速率限制 | ||
/// </summary> | ||
public bool EnableEndpointRateLimiting { get; set; } | ||
|
||
/// <summary> | ||
/// 禁用速率限制头部 | ||
/// </summary> | ||
public bool DisableRateLimitHeaders { get; set; } | ||
|
||
/// <summary> | ||
/// 启用正则规则匹配 | ||
/// </summary> | ||
public bool EnableRegexRuleMatching { get; set; } | ||
} | ||
|
||
public class GeneralRules | ||
{ | ||
public string Endpoint { get; set; } | ||
public string Period { get; set; } | ||
public int Limit { get; set; } | ||
} |
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
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
Oops, something went wrong.