@@ -494,22 +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
509- core .table .insert (plugins , plugin_obj )
510- core .table .insert (plugins , plugin_conf )
511507 end
512508
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 plugin_obj .type == " auth" ) then
516+ plugin_conf ._skip_rewrite_in_consumer = true
517+ end
518+
519+ if plugin_conf ._meta and plugin_conf ._meta .priority then
520+ custom_sort = true
521+ end
522+
523+ core .table .insert (plugins , plugin_obj )
524+ core .table .insert (plugins , plugin_conf )
525+
513526 :: continue::
514527 end
515528
@@ -523,15 +536,6 @@ function _M.filter(ctx, conf, plugins, route_conf, phase)
523536 local plugin_obj = plugins [i ]
524537 local plugin_conf = plugins [i + 1 ]
525538
526- -- in the rewrite phase, the plugin executes in the following order:
527- -- 1. execute the rewrite phase of the plugins on route(including the auth plugins)
528- -- 2. merge plugins from consumer and route
529- -- 3. execute the rewrite phase of the plugins on consumer(phase: rewrite_in_consumer)
530- -- in this case, we need to skip the plugins that was already executed(step 1)
531- if phase == " rewrite_in_consumer" and not plugin_conf ._from_consumer then
532- plugin_conf ._skip_rewrite_in_consumer = true
533- end
534-
535539 tmp_plugin_objs [plugin_conf ] = plugin_obj
536540 core .table .insert (tmp_plugin_confs , plugin_conf )
537541
@@ -1179,20 +1183,13 @@ function _M.run_plugin(phase, plugins, api_ctx)
11791183 and phase ~= " delayed_body_filter"
11801184 then
11811185 for i = 1 , # plugins , 2 do
1182- local phase_func
1183- if phase == " rewrite_in_consumer" then
1184- if plugins [i ].type == " auth" then
1185- plugins [i + 1 ]._skip_rewrite_in_consumer = true
1186- end
1187- phase_func = plugins [i ][" rewrite" ]
1188- else
1189- phase_func = plugins [i ][phase ]
1190- end
11911186
11921187 if phase == " rewrite_in_consumer" and plugins [i + 1 ]._skip_rewrite_in_consumer then
11931188 goto CONTINUE
11941189 end
11951190
1191+ local phase_func = phase == " rewrite_in_consumer" and plugins [i ][" rewrite" ]
1192+ or plugins [i ][phase ]
11961193 if phase_func then
11971194 local conf = plugins [i + 1 ]
11981195 if not meta_filter (api_ctx , plugins [i ][" name" ], conf )then
0 commit comments