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)