fix(server): 限流中间件 fail-close 安全加固
RateLimitConfig 添加 fail_close 字段(默认 true),Redis 不可达时 拒绝请求返回 503 而非静默放行。开发环境可通过 ERP__RATE_LIMIT__FAIL_CLOSE=false 回退旧行为。
This commit is contained in:
@@ -159,8 +159,26 @@ impl StorageConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
pub struct RateLimitConfig {}
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct RateLimitConfig {
|
||||
/// Redis 不可达时是否拒绝请求(fail-close)。
|
||||
/// true = 安全优先,Redis 故障时返回 503。
|
||||
/// false = 可用性优先,Redis 故障时放行。
|
||||
#[serde(default = "default_fail_close")]
|
||||
pub fail_close: bool,
|
||||
}
|
||||
|
||||
fn default_fail_close() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl Default for RateLimitConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
fail_close: default_fail_close(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn load() -> anyhow::Result<Self> {
|
||||
|
||||
Reference in New Issue
Block a user