This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2e5f982  Refactor the way to run global rule in log/header filter/body 
filter  (#1393)
2e5f982 is described below

commit 2e5f9824598506820b8e0fb937d25f6e9557c724
Author: Ayeshmantha Perera <[email protected]>
AuthorDate: Sat Apr 4 02:23:36 2020 +0200

    Refactor the way to run global rule in log/header filter/body filter  
(#1393)
---
 apisix/init.lua | 49 +++++++++----------------------------------------
 1 file changed, 9 insertions(+), 40 deletions(-)

diff --git a/apisix/init.lua b/apisix/init.lua
index 272911a..550afa1 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -436,8 +436,7 @@ function _M.grpc_access_phase()
     run_plugin("access", plugins, api_ctx)
 end
 
-
-function _M.http_header_filter_phase()
+local function common_phase(plugin_name)
     local api_ctx = ngx.ctx.api_ctx
     if not api_ctx then
         return
@@ -450,54 +449,25 @@ function _M.http_header_filter_phase()
         for _, global_rule in ipairs(router.global_rules.values) do
             core.table.clear(plugins)
             plugins = plugin.filter(global_rule, plugins)
-            run_plugin("header_filter", plugins, api_ctx)
+            run_plugin(plugin_name, plugins, api_ctx)
         end
         core.tablepool.release("plugins", plugins)
     end
-    run_plugin("header_filter", nil, api_ctx)
+    run_plugin(plugin_name, nil, api_ctx)
+    return api_ctx
 end
 
+function _M.http_header_filter_phase()
+    common_phase("header_filter")
+end
 
 function _M.http_body_filter_phase()
-    local api_ctx = ngx.ctx.api_ctx
-    if not api_ctx then
-        return
-    end
-
-    if router.global_rules and router.global_rules.values
-            and #router.global_rules.values > 0
-    then
-        local plugins = core.tablepool.fetch("plugins", 32, 0)
-        for _, global_rule in ipairs(router.global_rules.values) do
-            core.table.clear(plugins)
-            plugins = plugin.filter(global_rule, plugins)
-            run_plugin("body_filter", plugins, api_ctx)
-        end
-        core.tablepool.release("plugins", plugins)
-    end
-    run_plugin("body_filter", nil, api_ctx)
+    common_phase("body_filter")
 end
 
-
 function _M.http_log_phase()
-    local api_ctx = ngx.ctx.api_ctx
-    if not api_ctx then
-        return
-    end
-
-    if router.global_rules and router.global_rules.values
-            and #router.global_rules.values > 0
-    then
-        local plugins = core.tablepool.fetch("plugins", 32, 0)
-        for _, global_rule in ipairs(router.global_rules.values) do
-            core.table.clear(plugins)
-            plugins = plugin.filter(global_rule, plugins)
-            run_plugin("log", plugins, api_ctx)
-        end
-        core.tablepool.release("plugins", plugins)
-    end
 
-    run_plugin("log", nil, api_ctx)
+    local api_ctx = common_phase("log")
 
     if api_ctx.uri_parse_param then
         core.tablepool.release("uri_parse_param", api_ctx.uri_parse_param)
@@ -511,7 +481,6 @@ function _M.http_log_phase()
     core.tablepool.release("api_ctx", api_ctx)
 end
 
-
 function _M.http_balancer_phase()
     local api_ctx = ngx.ctx.api_ctx
     if not api_ctx then

Reply via email to