This is an automated email from the ASF dual-hosted git repository. spacewander pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new b78c87a fix: set conf info when global rule is hit without matched rule (#3332) b78c87a is described below commit b78c87a158b1eb5926dc70b462f1ae4c4eab8ec5 Author: 罗泽轩 <spacewander...@gmail.com> AuthorDate: Tue Jan 19 21:21:02 2021 -0600 fix: set conf info when global rule is hit without matched rule (#3332) Fix #3330 Signed-off-by: spacewander <spacewander...@gmail.com> --- apisix/init.lua | 12 ++++++++++++ t/config-center-yaml/global-rule.t | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/apisix/init.lua b/apisix/init.lua index 7188d2a..4f13603 100644 --- a/apisix/init.lua +++ b/apisix/init.lua @@ -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 diff --git a/t/config-center-yaml/global-rule.t b/t/config-center-yaml/global-rule.t index 00813fa..67bc24a 100644 --- a/t/config-center-yaml/global-rule.t +++ b/t/config-center-yaml/global-rule.t @@ -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