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

monkeydluffy 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 abcb49e01 fix: body-transformer should have a smaller priority than 
proxy-cache (#9267)
abcb49e01 is described below

commit abcb49e019e7bbd5ceb7cba2c71ef4c4119bdc45
Author: Sn0rt <[email protected]>
AuthorDate: Tue Apr 18 09:46:27 2023 +0800

    fix: body-transformer should have a smaller priority than proxy-cache 
(#9267)
---
 apisix/plugins/proxy-cache/init.lua |   2 +-
 conf/config-default.yaml            |   2 +-
 t/admin/plugins.t                   |   2 +-
 t/debug/debug-mode.t                |   2 +-
 t/plugin/body-transformer.t         | 112 ++++++++++++++++++++++++++++++++++++
 5 files changed, 116 insertions(+), 4 deletions(-)

diff --git a/apisix/plugins/proxy-cache/init.lua 
b/apisix/plugins/proxy-cache/init.lua
index 59569980c..333c20e20 100644
--- a/apisix/plugins/proxy-cache/init.lua
+++ b/apisix/plugins/proxy-cache/init.lua
@@ -108,7 +108,7 @@ local schema = {
 
 local _M = {
     version = 0.2,
-    priority = 1009,
+    priority = 1085,
     name = plugin_name,
     schema = schema,
 }
diff --git a/conf/config-default.yaml b/conf/config-default.yaml
index d61f745af..4f97adc4e 100755
--- a/conf/config-default.yaml
+++ b/conf/config-default.yaml
@@ -444,9 +444,9 @@ plugins:                          # plugin list (sorted by 
priority)
   - opa                            # priority: 2001
   - authz-keycloak                 # priority: 2000
   #- error-log-logger              # priority: 1091
+  - proxy-cache                    # priority: 1085
   - body-transformer               # priority: 1080
   - proxy-mirror                   # priority: 1010
-  - proxy-cache                    # priority: 1009
   - proxy-rewrite                  # priority: 1008
   - workflow                       # priority: 1006
   - api-breaker                    # priority: 1005
diff --git a/t/admin/plugins.t b/t/admin/plugins.t
index e8a82171e..ceb4df15b 100644
--- a/t/admin/plugins.t
+++ b/t/admin/plugins.t
@@ -88,9 +88,9 @@ consumer-restriction
 forward-auth
 opa
 authz-keycloak
+proxy-cache
 body-transformer
 proxy-mirror
-proxy-cache
 proxy-rewrite
 workflow
 api-breaker
diff --git a/t/debug/debug-mode.t b/t/debug/debug-mode.t
index ca0798ce0..5d645e8e6 100644
--- a/t/debug/debug-mode.t
+++ b/t/debug/debug-mode.t
@@ -61,8 +61,8 @@ loaded plugin and sort by priority: 2510 name: jwt-auth
 loaded plugin and sort by priority: 2500 name: key-auth
 loaded plugin and sort by priority: 2400 name: consumer-restriction
 loaded plugin and sort by priority: 2000 name: authz-keycloak
+loaded plugin and sort by priority: 1085 name: proxy-cache
 loaded plugin and sort by priority: 1010 name: proxy-mirror
-loaded plugin and sort by priority: 1009 name: proxy-cache
 loaded plugin and sort by priority: 1008 name: proxy-rewrite
 loaded plugin and sort by priority: 1005 name: api-breaker
 loaded plugin and sort by priority: 1003 name: limit-conn
diff --git a/t/plugin/body-transformer.t b/t/plugin/body-transformer.t
index ae2211de4..be07f9ac0 100644
--- a/t/plugin/body-transformer.t
+++ b/t/plugin/body-transformer.t
@@ -652,3 +652,115 @@ foobar:
             assert(res.status == 200)
         }
     }
+
+
+
+=== TEST 10: cooperation of proxy-cache plugin
+--- http_config
+lua_shared_dict memory_cache 50m;
+--- config
+location /demo {
+    content_by_lua_block {
+        ngx.say([[
+    <SOAP-ENV:Envelope
+        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";>
+    <SOAP-ENV:Header/>
+        <SOAP-ENV:Body>
+            <ns2:CapitalCityResponse
+                xmlns:ns2="http://spring.io/guides/gs-producing-web-service";>
+                <ns2:CapitalCityResult>hello</ns2:CapitalCityResult>
+            </ns2:CapitalCityResponse>
+        </SOAP-ENV:Body>
+    </SOAP-ENV:Envelope>
+        ]])
+    }
+}
+
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin")
+
+            local req_template = ngx.encode_base64[[
+                <soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:web="http://www.oorsprong.org/websamples.countryinfo";>
+                <soapenv:Header/>
+                <soapenv:Body>
+                    <web:CapitalCity>
+                    
<web:sCountryISOCode>{{_escape_xml(country)}}</web:sCountryISOCode>
+                    </web:CapitalCity>
+                </soapenv:Body>
+                </soapenv:Envelope>
+            ]]
+
+            local rsp_template = ngx.encode_base64[[
+                {"result": 
{*_escape_json(Envelope.Body.CapitalCityResponse.CapitalCityResult)*}}
+                ]]
+
+            local code, body = t.test('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                string.format([[{
+                    "uri": "/capital",
+                    "plugins": {
+                        "proxy-rewrite": {
+                            "set": {
+                                "Accept-Encoding": "identity",
+                                "Content-Type": "text/xml"
+                            },
+                            "uri": "/demo"
+                        },
+                        "proxy-cache":{
+                            "cache_strategy": "memory",
+                            "cache_bypass": ["$arg_bypass"],
+                            "cache_http_status": [200],
+                            "cache_key": ["$uri", "-cache-id"],
+                            "cache_method": ["POST"],
+                            "hide_cache_headers": true,
+                            "no_cache": ["$arg_test"],
+                            "cache_zone": "memory_cache"
+                        },
+                        "body-transformer": {
+                            "request": {
+                                "input_format": "json",
+                                "template": "%s"
+                            },
+                            "response": {
+                                "input_format": "xml",
+                                "template": "%s"
+                            }
+                        },
+                        "response-rewrite":{
+                            "headers": {
+                                "set": {
+                                    "Content-Type": "application/json"
+                                }
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:%d": 1
+                        }
+                    }
+                }]], req_template, rsp_template, ngx.var.server_port)
+            )
+
+            local core = require("apisix.core")
+            local http = require("resty.http")
+            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. 
"/capital"
+            local body = [[{"country": "foo"}]]
+            local opt = {method = "POST", body = body}
+            local httpc = http.new()
+
+            local res = httpc:request_uri(uri, opt)
+            assert(res.status == 200)
+            local data = core.json.decode(res.body)
+            assert(data.result == "hello")
+            assert(res.headers["Apisix-Cache-Status"] == "MISS")
+
+            local res2 = httpc:request_uri(uri, opt)
+            assert(res2.status == 200)
+            local data2 = core.json.decode(res2.body)
+            assert(data2.result == "hello")
+            assert(res2.headers["Apisix-Cache-Status"] == "HIT")
+        }
+    }

Reply via email to