kingluo opened a new issue, #9226:
URL: https://github.com/apache/apisix/issues/9226

   ### Current Behavior
   
   If we use the memory cache type in proxy-cache, then the body-transformer 
will not work.
   Because currently, the proxy-rewrite runs the body filter after the 
body-transformer, so it caches the transformed body but not the original one 
from upstream. At the next request, the cache will hit and provide the 
transformed body to the body-transformer, it failed.
   
   
   ### Expected Behavior
   
   The proxy-cache should cache the original response from the upstream.
   
   ### Error Logs
   
   2023/04/03 16:40:32 [error] 2705998#2705998: *279 [lua] 
body-transformer.lua:123: transform(): response body decode: 
/opt/apisix//deps/share/lua/5.1/xml2lua.lua:92: Err
   or Parsing XML [char=1]
   , body={"result": "hello"}, client: 127.0.0.1, server: _, request: "POST 
/capital HTTP/1.1", host: "127.0.0.1:9080"
   
   ### Steps to Reproduce
   
   ```
   c put /routes/1 -d '
   {
     "uri":"/capital",
     "name":"TempConvertRoute",
     "methods":[
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE",
       "PURGE"
     ],
     "plugins":{
       "body-transformer":{
         "request":{
           "input_format":"json",
           "template":"<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>"
         },
         "response":{
           "input_format":"xml",
           "template":"{\"result\": 
{*_escape_json(Envelope.Body.CapitalCityResponse.CapitalCityResult)*}}"
         }
       },
       "file-logger":{
         "path":"logs/file.log"
       },
       "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"
       },
       "proxy-rewrite":{
         "headers":{
           "set":{
             "Accept-Encoding":"identity",
             "Content-Type":"text/xml"
           }
         },
         "uri":"/websamples.countryinfo/CountryInfoService.wso"
       },
       "response-rewrite":{
         "headers":{
           "set":{
             "Content-Type":"application/json"
           }
         }
       }
     },
     "upstream":{
       "nodes":{
         "localhost:3000":1
       }
     },
     "status":1
   }
   '
   
   d post /capital -d '{"country":"foo"}' -v
   ```
   
   ### Environment
   
   - APISIX version (run `apisix version`): master
   - Operating system (run `uname -a`):
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to