AspNetCoreRateLimit 端点通配符不起作用
AspNetCoreRateLimit endpoint wild-card does not work
我正在尝试使用 AspNetCoreRateLimit package 实施速率限制。我只想限制一个端点的速率这个:
https://[removed for privacy]/v/1/product_provisioning/user_has_signatures?phoneNumber=070930900
当我将此配置与 *
通配符一起使用时,我得到了所有端点的正确速率限制,但是 我只想为上面提到的端点实施它:
"IpRateLimiting": {
"EnableEndpointRateLimiting": false,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "60s",
"Limit": 1
}
]
}
我尝试了以下通配符组合并且 none 成功了:
"Endpoint": "*:/v/1/product_provisioning/*",
"Endpoint": "GET:/v/1/product_provisioning/*",
"Endpoint": "*:/v/1/product_provisioning/user_has_signatures/*",
"Endpoint": "*:/v/1/product_provisioning/user_has_signatures?phoneNumber=*",
因为你的phoneNumber
是查询字符串,
options.EnableEndpointRateLimiting = true;
options.StackBlockedRequests = false;
options.HttpStatusCode = 429;
options.RealIpHeader = "X-Real-IP";
options.ClientIdHeader = "X-ClientId";
options.GeneralRules = new List<RateLimitRule>
{
new RateLimitRule
{
Endpoint = "GET:/v/1/product_provisioning/user_has_signatures",
Period = "60s",
Limit = 1,
}
};
在上面的代码中,选项 EnableEndpointRateLimiting
设置为 true 以确保将限制应用于特定端点而不是所有端点。如果 EnableEndpointRateLimiting
设置为 false,则限制将在全球范围内应用,并且仅适用具有作为端点 * 的规则。
我正在尝试使用 AspNetCoreRateLimit package 实施速率限制。我只想限制一个端点的速率这个:
https://[removed for privacy]/v/1/product_provisioning/user_has_signatures?phoneNumber=070930900
当我将此配置与 *
通配符一起使用时,我得到了所有端点的正确速率限制,但是 我只想为上面提到的端点实施它:
"IpRateLimiting": {
"EnableEndpointRateLimiting": false,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "60s",
"Limit": 1
}
]
}
我尝试了以下通配符组合并且 none 成功了:
"Endpoint": "*:/v/1/product_provisioning/*",
"Endpoint": "GET:/v/1/product_provisioning/*",
"Endpoint": "*:/v/1/product_provisioning/user_has_signatures/*",
"Endpoint": "*:/v/1/product_provisioning/user_has_signatures?phoneNumber=*",
因为你的phoneNumber
是查询字符串,
options.EnableEndpointRateLimiting = true;
options.StackBlockedRequests = false;
options.HttpStatusCode = 429;
options.RealIpHeader = "X-Real-IP";
options.ClientIdHeader = "X-ClientId";
options.GeneralRules = new List<RateLimitRule>
{
new RateLimitRule
{
Endpoint = "GET:/v/1/product_provisioning/user_has_signatures",
Period = "60s",
Limit = 1,
}
};
在上面的代码中,选项 EnableEndpointRateLimiting
设置为 true 以确保将限制应用于特定端点而不是所有端点。如果 EnableEndpointRateLimiting
设置为 false,则限制将在全球范围内应用,并且仅适用具有作为端点 * 的规则。