feature: support to run header_filter and body_filter phase for global rules. (#1364)

This commit is contained in:
Ayeshmantha Perera 2020-04-02 02:46:00 +02:00 committed by GitHub
parent c76e7e3623
commit b61db0865a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -435,12 +435,44 @@ end
function _M.http_header_filter_phase() function _M.http_header_filter_phase()
run_plugin("header_filter") 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("header_filter", plugins, api_ctx)
end
core.tablepool.release("plugins", plugins)
end
run_plugin("header_filter", nil, api_ctx)
end end
function _M.http_body_filter_phase() function _M.http_body_filter_phase()
run_plugin("body_filter") 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("body_filter", plugins, api_ctx)
end
core.tablepool.release("plugins", plugins)
end
run_plugin("body_filter", nil, api_ctx)
end end
@ -451,7 +483,7 @@ function _M.http_log_phase()
end end
if router.global_rules and router.global_rules.values if router.global_rules and router.global_rules.values
and #router.global_rules.values > 0 and #router.global_rules.values > 0
then then
local plugins = core.tablepool.fetch("plugins", 32, 0) local plugins = core.tablepool.fetch("plugins", 32, 0)
for _, global_rule in ipairs(router.global_rules.values) do for _, global_rule in ipairs(router.global_rules.values) do