Skip to content

Commit 6a597cb

Browse files
committed
change: move plugin._skip_rewrite_in_consumer from _M.run_plugin into _M.filter
1 parent 9eab7f7 commit 6a597cb

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

apisix/plugin.lua

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -494,32 +494,35 @@ function _M.filter(ctx, conf, plugins, route_conf, phase)
494494
goto continue
495495
end
496496

497-
if not check_disable(plugin_conf) then
498-
if plugin_obj.run_policy == "prefer_route" and route_plugin_conf ~= nil then
499-
local plugin_conf_in_route = route_plugin_conf[name]
500-
local disable_in_route = check_disable(plugin_conf_in_route)
501-
if plugin_conf_in_route and not disable_in_route then
502-
goto continue
503-
end
504-
end
497+
if check_disable(plugin_conf) then
498+
goto continue
499+
end
505500

506-
if plugin_conf._meta and plugin_conf._meta.priority then
507-
custom_sort = true
501+
if plugin_obj.run_policy == "prefer_route" and route_plugin_conf ~= nil then
502+
local plugin_conf_in_route = route_plugin_conf[name]
503+
local disable_in_route = check_disable(plugin_conf_in_route)
504+
if plugin_conf_in_route and not disable_in_route then
505+
goto continue
508506
end
507+
end
509508

510-
-- in the rewrite phase, the plugin executes in the following order:
511-
-- 1. execute the rewrite phase of the plugins on route(including the auth plugins)
512-
-- 2. merge plugins from consumer and route
513-
-- 3. execute the rewrite phase of the plugins on consumer(phase: rewrite_in_consumer)
514-
-- in this case, we need to skip the plugins that was already executed(step 1)
515-
if phase == "rewrite_in_consumer" and not plugin_conf._from_consumer then
516-
plugin_conf._skip_rewrite_in_consumer = true
517-
end
509+
-- in the rewrite phase, the plugin executes in the following order:
510+
-- 1. execute the rewrite phase of the plugins on route(including the auth plugins)
511+
-- 2. merge plugins from consumer and route
512+
-- 3. execute the rewrite phase of the plugins on consumer(phase: rewrite_in_consumer)
513+
-- in this case, we need to skip the plugins that was already executed(step 1)
514+
if phase == "rewrite_in_consumer"
515+
and (not plugin_conf._from_consumer or plugins.type == "auth") then
516+
plugin_conf._skip_rewrite_in_consumer = true
517+
end
518518

519-
core.table.insert(plugins, plugin_obj)
520-
core.table.insert(plugins, plugin_conf)
519+
if plugin_conf._meta and plugin_conf._meta.priority then
520+
custom_sort = true
521521
end
522522

523+
core.table.insert(plugins, plugin_obj)
524+
core.table.insert(plugins, plugin_conf)
525+
523526
::continue::
524527
end
525528

@@ -1180,20 +1183,13 @@ function _M.run_plugin(phase, plugins, api_ctx)
11801183
and phase ~= "delayed_body_filter"
11811184
then
11821185
for i = 1, #plugins, 2 do
1183-
local phase_func
1184-
if phase == "rewrite_in_consumer" then
1185-
if plugins[i].type == "auth" then
1186-
plugins[i + 1]._skip_rewrite_in_consumer = true
1187-
end
1188-
phase_func = plugins[i]["rewrite"]
1189-
else
1190-
phase_func = plugins[i][phase]
1191-
end
11921186

11931187
if phase == "rewrite_in_consumer" and plugins[i + 1]._skip_rewrite_in_consumer then
11941188
goto CONTINUE
11951189
end
11961190

1191+
local phase_func = phase == "rewrite_in_consumer" and plugins[i]["rewrite"]
1192+
or plugins[i][phase]
11971193
if phase_func then
11981194
local conf = plugins[i + 1]
11991195
if not meta_filter(api_ctx, plugins[i]["name"], conf)then

0 commit comments

Comments
 (0)