Skip to content

Commit

Permalink
fix: set conf info when global rule is hit without matched rule (#3332)
Browse files Browse the repository at this point in the history
Fix #3330

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored Jan 20, 2021
1 parent 746345a commit b78c87a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions t/config-center-yaml/global-rule.t
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b78c87a

Please sign in to comment.