fix: set conf info when global rule is hit without matched rule (#3332)

Fix #3330

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
罗泽轩 2021-01-19 21:21:02 -06:00 committed by GitHub
parent 746345aab2
commit b78c87a158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -610,14 +610,26 @@ local function common_phase(phase_name)
end
if api_ctx.global_rules then
local orig_conf_type = api_ctx.conf_type
local orig_conf_version = api_ctx.conf_version
local orig_conf_id = api_ctx.conf_id
local plugins = core.tablepool.fetch("plugins", 32, 0)
local values = api_ctx.global_rules.values
for _, global_rule in config_util.iterate_values(values) do
api_ctx.conf_type = "global_rule"
api_ctx.conf_version = global_rule.modifiedIndex
api_ctx.conf_id = global_rule.value.id
core.table.clear(plugins)
plugins = plugin.filter(global_rule, plugins)
run_plugin(phase_name, plugins, api_ctx)
end
core.tablepool.release("plugins", plugins)
api_ctx.conf_type = orig_conf_type
api_ctx.conf_version = orig_conf_version
api_ctx.conf_id = orig_conf_id
end
if api_ctx.script_obj then

View File

@ -112,3 +112,18 @@ global_rules:
- /h*
#END
--- error_code: 403
=== TEST 4: common phase without matched route
--- apisix_yaml
global_rules:
-
id: 1
plugins:
cors:
allow_origins: "a.com,b.com"
#END
--- request
GET /apisix/prometheus/metrics
--- error_code: 200