-
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.
- 支持自定义限流 - 支持限流自定义模板
- Loading branch information
Showing
21 changed files
with
1,084 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,91 @@ | ||
using System.Threading.RateLimiting; | ||
|
||
namespace FastGateway.Domain; | ||
namespace FastGateway.Domain; | ||
|
||
public sealed class RateLimit | ||
{ | ||
public RateLimitType Type { get; set; } | ||
|
||
#region 固定窗口限制器 | ||
/// <summary> | ||
/// 限流策略名称 | ||
/// </summary> | ||
[Column(IsIdentity = true)] | ||
public string Name { get; set; } | ||
|
||
public int? PermitLimit { get; set; } | ||
/// <summary> | ||
/// 是否启用 | ||
/// </summary> | ||
public bool Enable { get; set; } | ||
|
||
/// <summary> | ||
/// 限流时间窗口 | ||
/// 通用规则列表 | ||
/// </summary> | ||
public TimeSpan? Window { get; set; } | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<GeneralRules> GeneralRules { get; set; } | ||
|
||
/// <summary> | ||
/// QueueProcessingOrder | ||
/// 端点白名单 | ||
/// </summary> | ||
public QueueProcessingOrder? QueueProcessingOrder { get; set; } | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<string> EndpointWhitelist { get; set; } | ||
|
||
/// <summary> | ||
/// QueueLimit | ||
/// 客户端ID头部 | ||
/// </summary> | ||
public int? QueueLimit { get; set; } | ||
public string ClientIdHeader { get; set; } = "X-ClientId"; | ||
|
||
#endregion | ||
/// <summary> | ||
/// 客户端白名单 | ||
/// </summary> | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<string> ClientWhitelist { get; set; } | ||
|
||
#region 滑动窗口限制器 | ||
/// <summary> | ||
/// 真实IP头部 | ||
/// </summary> | ||
public string RealIpHeader { get; set; } = "X-Real-IP"; | ||
|
||
/// <summary> | ||
/// SegmentsPerWindow | ||
/// IP白名单 | ||
/// </summary> | ||
public int? SegmentsPerWindow { get; set; } | ||
[Column(MapType = typeof(string), StringLength = -1)] | ||
public List<string> IpWhitelist { get; set; } | ||
|
||
#endregion | ||
/// <summary> | ||
/// HTTP状态码 | ||
/// </summary> | ||
public int HttpStatusCode { get; set; } = 429; | ||
|
||
#region 令牌桶限制器 | ||
/// <summary> | ||
/// 超出配额消息 | ||
/// </summary> | ||
public string QuotaExceededMessage { get; set; } | ||
|
||
/// <summary> | ||
/// TokenLimit | ||
/// 错误内容类型 | ||
/// </summary> | ||
public int? TokenLimit { get; set; } | ||
public string RateLimitContentType { get; set; } = "text/html"; | ||
|
||
/// <summary> | ||
/// TokensPerPeriod | ||
/// 速率限制计数器前缀 | ||
/// </summary> | ||
public int? TokensPerPeriod { get; set; } | ||
public string RateLimitCounterPrefix { get; set; } = "crlc"; | ||
|
||
/// <summary> | ||
/// AutoReplenishment | ||
/// 启用端点速率限制 | ||
/// </summary> | ||
public bool? AutoReplenishment { get; set; } | ||
public bool EnableEndpointRateLimiting { get; set; } | ||
|
||
#endregion | ||
/// <summary> | ||
/// 禁用速率限制头部 | ||
/// </summary> | ||
public bool DisableRateLimitHeaders { get; set; } | ||
|
||
/// <summary> | ||
/// 拒绝响应状态码 | ||
/// 启用正则规则匹配 | ||
/// </summary> | ||
public int RejectionStatusCode { get; set; } | ||
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.