You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/11/10 01:58:17 UTC
[apisix] 16/18: fix: APISIX extended variables cannot be used in `_meta.filter` (#8256)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch release/2.15
in repository https://gitbox.apache.org/repos/asf/apisix.git
commit c020f0eb06e0d011eebc7564632286e9574c8834
Author: soulbird <zh...@outlook.com>
AuthorDate: Mon Nov 7 15:02:28 2022 +0800
fix: APISIX extended variables cannot be used in `_meta.filter` (#8256)
Co-authored-by: soulbird <zh...@gmail.com>
Fixes https://github.com/apache/apisix/issues/8251
---
apisix/plugin.lua | 2 +-
t/plugin/plugin.t | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 511fbc605..7224e3492 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -425,7 +425,7 @@ local function meta_filter(ctx, plugin_name, plugin_conf)
" plugin_name: ", plugin_name)
return true
end
- ok, err = ex:eval()
+ ok, err = ex:eval(ctx.var)
if err then
core.log.warn("failed to run the 'vars' expression: ", err,
" plugin_name: ", plugin_name)
diff --git a/t/plugin/plugin.t b/t/plugin/plugin.t
index 248688050..7ad45bc0d 100644
--- a/t/plugin/plugin.t
+++ b/t/plugin/plugin.t
@@ -735,3 +735,55 @@ passed
GET /hello
--- response_headers
!x-version
+
+
+
+=== TEST 29: use APISIX's built-in variables in meta.filter
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ {
+ plugins = {
+ ["proxy-rewrite"] = {
+ _meta = {
+ filter = {
+ {"post_arg_key", "==", "abc"}
+ }
+ },
+ uri = "/echo",
+ headers = {
+ ["X-Api-Version"] = "ga"
+ }
+ }
+ },
+ upstream = {
+ nodes = {
+ ["127.0.0.1:1980"] = 1
+ }
+ },
+ uri = "/hello"
+ }
+ )
+ if code >= 300 then
+ ngx.print(body)
+ else
+ ngx.say(body)
+ end
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 30: hit route: proxy-rewrite enable with post_arg_xx in meta.filter
+--- request
+POST /hello
+key=abc
+--- more_headers
+Content-Type: application/x-www-form-urlencoded
+--- response_headers
+x-api-version: ga