Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the way to run global rule in log/header filter/body filter … #1392

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 23 additions & 49 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -436,82 +436,56 @@ function _M.grpc_access_phase()
run_plugin("access", plugins, api_ctx)
end


function _M.http_header_filter_phase()
local api_ctx = ngx.ctx.api_ctx
if not api_ctx then
return
end

local function common_phase(plugin_name,api_ctx)
if router.global_rules and router.global_rules.values
and #router.global_rules.values > 0
then
local plugins = core.tablepool.fetch("plugins", 32, 0)
for _, global_rule in ipairs(router.global_rules.values) do
core.table.clear(plugins)
plugins = plugin.filter(global_rule, plugins)
run_plugin("header_filter", plugins, api_ctx)
run_plugin(plugin_name, plugins, api_ctx)
end
core.tablepool.release("plugins", plugins)
end
run_plugin("header_filter", nil, api_ctx)
end
run_plugin(plugin_name, nil, api_ctx)

if api_ctx.uri_parse_param then
core.tablepool.release("uri_parse_param", api_ctx.uri_parse_param)
end

function _M.http_body_filter_phase()
core.ctx.release_vars(api_ctx)
if api_ctx.plugins then
core.tablepool.release("plugins", api_ctx.plugins)
end

core.tablepool.release("api_ctx", api_ctx)
end

function _M.http_header_filter_phase()
local api_ctx = ngx.ctx.api_ctx
if not api_ctx then
return
end
common_phase("header_filter", api_ctx)
end

if router.global_rules and router.global_rules.values
and #router.global_rules.values > 0
then
local plugins = core.tablepool.fetch("plugins", 32, 0)
for _, global_rule in ipairs(router.global_rules.values) do
core.table.clear(plugins)
plugins = plugin.filter(global_rule, plugins)
run_plugin("body_filter", plugins, api_ctx)
end
core.tablepool.release("plugins", plugins)
function _M.http_body_filter_phase()
local api_ctx = ngx.ctx.api_ctx
if not api_ctx then
return
end
run_plugin("body_filter", nil, api_ctx)
common_phase("body_filter", api_ctx)
end


function _M.http_log_phase()
local api_ctx = ngx.ctx.api_ctx
if not api_ctx then
return
end

if router.global_rules and router.global_rules.values
and #router.global_rules.values > 0
then
local plugins = core.tablepool.fetch("plugins", 32, 0)
for _, global_rule in ipairs(router.global_rules.values) do
core.table.clear(plugins)
plugins = plugin.filter(global_rule, plugins)
run_plugin("log", plugins, api_ctx)
end
core.tablepool.release("plugins", plugins)
end

run_plugin("log", nil, api_ctx)

if api_ctx.uri_parse_param then
core.tablepool.release("uri_parse_param", api_ctx.uri_parse_param)
end

core.ctx.release_vars(api_ctx)
if api_ctx.plugins then
core.tablepool.release("plugins", api_ctx.plugins)
end

core.tablepool.release("api_ctx", api_ctx)
common_phase("log", api_ctx)
end


function _M.http_balancer_phase()
local api_ctx = ngx.ctx.api_ctx
if not api_ctx then
Expand Down