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 2022/10/25 09:42:09 UTC

[GitHub] [apisix] tokers commented on a diff in pull request #8162: fix: meta.filter in plugin doesn't work in response-rewrite plugin

tokers commented on code in PR #8162:
URL: https://github.com/apache/apisix/pull/8162#discussion_r1004243260


##########
apisix/plugin.lua:
##########
@@ -415,6 +415,11 @@ local function meta_filter(ctx, plugin_name, plugin_conf)
         return true
     end
 
+    local match_cache_key = ctx.conf_type .. plugin_name .. "meta_filter_matched"

Review Comment:
   Use some separator like `#` before `meta_filter_matched` ?



##########
apisix/plugin.lua:
##########
@@ -920,6 +925,8 @@ function _M.run_plugin(phase, plugins, api_ctx)
         return api_ctx
     end
 
+    --local matched = meta_filter(ctx, name, plugin_conf)

Review Comment:
   Remove this?



##########
t/plugin/plugin.t:
##########
@@ -525,3 +525,170 @@ passed
 GET /hello1?version=v4
 --- response_headers
 x-api-version: v4
+
+
+
+=== TEST 19: use _meta.filter in response-rewrite plugin
+--- 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": {
+                            "response-rewrite": {
+                                "_meta": {
+                                    "filter": [
+                                        ["upstream_status", "~=", 200]
+                                    ]
+                                },
+                                "headers": {
+                                    "set": {
+                                        "test-header": "error"
+                                    }
+                                }
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/*"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 20: upstream_status = 502, enable response-rewrite plugin
+--- request
+GET /specific_status
+--- more_headers
+x-test-upstream-status: 502
+--- response_headers
+test-header: error
+--- error_code: 502
+
+
+
+=== TEST 21: upstream_status = 200, disable response-rewrite plugin
+--- request
+GET /hello
+

Review Comment:
   Should check if the `x-test-upstream-status` doesn't exist.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

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