show name of module that filtered request in logs

This commit is contained in:
Luna 2022-12-07 01:49:00 -03:00
parent 0c0b842370
commit fb43b80e6b

View file

@ -34,15 +34,16 @@ function ctx:onRequest()
for callback_regex, callback_function in pairs(module.callbacks) do for callback_regex, callback_function in pairs(module.callbacks) do
local match, error = ngx.re.match(request_uri, callback_regex) local match, error = ngx.re.match(request_uri, callback_regex)
if match then if match then
table.insert(callbacks_to_call, {callback_function, module_config, state}) table.insert(callbacks_to_call, {module, callback_function, module_config, state})
end end
end end
end end
for _,tuple in ipairs(callbacks_to_call) do for _, tuple in ipairs(callbacks_to_call) do
local callback_function, config, state = unpack(tuple) local module, callback_function, config, state = unpack(tuple)
local status_code, body = callback_function(config, state) local status_code, body = callback_function(config, state)
if status_code ~= nil then if status_code ~= nil then
log('filtered by module ' .. module.name)
ngx.status = status_code ngx.status = status_code
ngx.say(body or "request denied") ngx.say(body or "request denied")
ngx.exit(status_code) ngx.exit(status_code)