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

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

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,26 @@ local function common_phase(phase_name)
end

if api_ctx.global_rules then
local orig_conf_type = api_ctx.conf_type
spacewander marked this conversation as resolved.
Show resolved Hide resolved
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
spacewander marked this conversation as resolved.
Show resolved Hide resolved
plugins:
cors:
allow_origins: "a.com,b.com"
#END
--- request
GET /apisix/prometheus/metrics
--- error_code: 200