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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2969a4b  refactor: exact APISIX vars (#5635)
2969a4b is described below

commit 2969a4bf55910dbbb75f44a4ea1779fbf40f68bf
Author: 罗泽轩 <[email protected]>
AuthorDate: Tue Nov 30 12:30:41 2021 +0800

    refactor: exact APISIX vars (#5635)
---
 apisix/core/ctx.lua | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/apisix/core/ctx.lua b/apisix/core/ctx.lua
index 30c7644..f07665a 100644
--- a/apisix/core/ctx.lua
+++ b/apisix/core/ctx.lua
@@ -143,6 +143,16 @@ do
         var_x_forwarded_proto = true,
     }
 
+    local apisix_var_names = {
+        route_id = true,
+        route_name = true,
+        service_id = true,
+        service_name = true,
+        consumer_name = true,
+        balancer_ip = true,
+        balancer_port = true,
+    }
+
     local mt = {
         __index = function(t, key)
             local cached = t._cache[key]
@@ -205,26 +215,8 @@ do
                 key = sub_str(key, 9)
                 val = get_parsed_graphql()[key]
 
-            elseif key == "route_id" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.route_id
-
-            elseif key == "service_id" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.service_id
-
-            elseif key == "consumer_name" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.consumer_name
-
-            elseif key == "route_name" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.route_name
-
-            elseif key == "service_name" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.service_name
-
-            elseif key == "balancer_ip" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.balancer_ip
-
-            elseif key == "balancer_port" then
-                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.balancer_port
+            elseif apisix_var_names[key] then
+                val = ngx.ctx.api_ctx and ngx.ctx.api_ctx[key]
 
             else
                 val = get_var(key, t._request)

Reply via email to