From ef0c5b96949f938d6d818035a4d7ed07bffb95aa Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 6 May 2026 20:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=9F=E7=8E=87=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/rate_limiter.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/rate_limiter.lua b/modules/rate_limiter.lua index e86977d..3c2b634 100644 --- a/modules/rate_limiter.lua +++ b/modules/rate_limiter.lua @@ -3,13 +3,12 @@ local _M = {} -local config_module = require "config.rate_limit_config" local common_config = require "config.common_config" local logger = require "lib.logger" --- 获取配置 +-- 获取配置(直接从公共配置读取) local function get_config() - return config_module.get_config() + return common_config.rate_limit end -- 检查域名是否应该应用限流 @@ -118,12 +117,12 @@ function _M.check_rate_limit() -- 检查是否超过限制 if new_count > max_requests then -- 根据配置的处置策略执行相应操作 - if cfg.action == config_module.ACTION_ALLOW then + if cfg.action == "allow" then -- 放行:仅记录日志,不阻止 logger.log_allowed(client_ip, new_count, time_window) return true - elseif cfg.action == config_module.ACTION_RATE_LIMIT then + elseif cfg.action == "rate_limit" then -- 限制速率:返回429 logger.log_rate_limited(client_ip, new_count, max_requests, time_window) @@ -132,7 +131,7 @@ function _M.check_rate_limit() ngx.say(cfg.message or "Rate limit exceeded") return false - elseif cfg.action == config_module.ACTION_BLOCK then + elseif cfg.action == "block" then -- 封禁:返回403 logger.log_blocked(client_ip, new_count, max_requests, time_window)