You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/07/01 01:56:41 UTC

[GitHub] [incubator-apisix] membphis commented on issue #1667: bug: global-rule error when enable_debug=true

membphis commented on issue #1667:
URL: https://github.com/apache/incubator-apisix/issues/1667#issuecomment-652140810


   many thanks to your PR, and I confirmed it should be a bug.
   
   I write a patch for this bug. You can take a look at this, and we need some test cases to confirm we fixed this bug:
   
   ```diff
   diff --git a/apisix/init.lua b/apisix/init.lua
   index 41295f0..3ecb999 100644
   --- a/apisix/init.lua
   +++ b/apisix/init.lua
   @@ -252,7 +252,7 @@ function _M.http_access_phase()
                api_ctx.conf_id = global_rule.value.id
   
                core.table.clear(plugins)
   -            api_ctx.plugins = plugin.filter(global_rule, plugins)
   +            api_ctx.plugins = plugin.filter(global_rule, plugins, true)
                run_plugin("rewrite", plugins, api_ctx)
                run_plugin("access", plugins, api_ctx)
            end
   @@ -445,8 +445,7 @@ local function common_phase(phase_name)
            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
   -            core.table.clear(plugins)
   -            plugins = plugin.filter(global_rule, plugins)
   +            plugins = plugin.filter(global_rule, plugins, true)
                run_plugin(phase_name, plugins, api_ctx)
            end
            core.tablepool.release("plugins", plugins)
   diff --git a/apisix/plugin.lua b/apisix/plugin.lua
   index 075d058..8267ae1 100644
   --- a/apisix/plugin.lua
   +++ b/apisix/plugin.lua
   @@ -232,14 +232,35 @@ function _M.api_routes()
    end
   
   
   -function _M.filter(user_route, plugins)
   +local function set_response_header_by_debug_flag(plugins, dry_run)
   +    if dry_run then
   +        return
   +    end
   +
   +    if not local_conf or not local_conf.apisix.enable_debug then
   +        return
   +    end
   +
   +    if #plugins == 0 then
   +        core.response.set_header("Apisix-Plugins", "no plugin")
   +    end
   +
   +    local t = {}
   +    for i = 1, #plugins, 2 do
   +        core.table.insert(t, plugins[i].name)
   +    end
   +    core.response.set_header("Apisix-Plugins", core.table.concat(t, ", "))
   +end
   +
   +
   +function _M.filter(user_route, plugins, dry_run)
        plugins = plugins or core.table.new(#local_plugins * 2, 0)
   +    core.table.clear(plugins)
   +
        local user_plugin_conf = user_route.value.plugins
        if user_plugin_conf == nil or
           core.table.nkeys(user_plugin_conf) == 0 then
   -        if local_conf and local_conf.apisix.enable_debug then
   -            core.response.set_header("Apisix-Plugins", "no plugin")
   -        end
   +        set_response_header_by_debug_flag(plugins, dry_run)
            return plugins
        end
   
   @@ -253,14 +274,7 @@ function _M.filter(user_route, plugins)
            end
        end
   
   -    if local_conf.apisix.enable_debug then
   -        local t = {}
   -        for i = 1, #plugins, 2 do
   -            core.table.insert(t, plugins[i].name)
   -        end
   -        core.response.set_header("Apisix-Plugins", core.table.concat(t, ", "))
   -    end
   -
   +    set_response_header_by_debug_flag(plugins, dry_run)
        return plugins
    end
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org