Firstsawyou commented on issue #3903:
URL: https://github.com/apache/apisix/issues/3903#issuecomment-807035124


   Hi, @Gary-Airwallex  Sorry, my previous test method was incorrect. I checked 
the latest version again, and there seems to be such a problem.   @spacewander  
Please take a look at this question when you are free.
   
   Here are the steps to reproduce:
   
   1. Add the log of `ctx.var.upstream_uri` in the rewrite phase of the `cors` 
plugin, and print the rewritten uri in the `proxy-rewrite` plugin.
   
   ```shell
   diff --git a/apisix/plugins/cors.lua b/apisix/plugins/cors.lua
   index 4b0b7c4..98beecc 100644
   --- a/apisix/plugins/cors.lua
   +++ b/apisix/plugins/cors.lua
   @@ -225,6 +225,7 @@ end
    
    
    function _M.rewrite(conf, ctx)
   +    core.log.warn("Access upstream uri: ", ctx.var.upstream_uri)
        if ctx.var.request_method == "OPTIONS" then
            return 200
        end
   diff --git a/apisix/plugins/proxy-rewrite.lua 
b/apisix/plugins/proxy-rewrite.lua
   index c678b59..e0c3d58 100644
   --- a/apisix/plugins/proxy-rewrite.lua
   +++ b/apisix/plugins/proxy-rewrite.lua
   @@ -179,6 +179,7 @@ function _M.rewrite(conf, ctx)
        end
    
        if not conf.headers then
   +        core.log.warn("upstream_uri: ", ctx.var.upstream_uri)
            return
        end
   ```
   
   2. Add the global plugin `cors`
   
   ```shell
   curl -X PUT http://127.0.0.1:9080/apisix/admin/global_rules/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -d '{
           "plugins": {
              "cors": {}
           }
   }'
   ```
   
   3. Add a route and bind the `proxy-rewrite` plugin
   
   ```shell
   curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "methods": ["GET"],
       "uri": "/hello",
       "plugins": {
           "proxy-rewrite": {
               "uri": "/route01"
           }
       },
       "upstream": {
           "type": "roundrobin",
           "nodes": {
               "127.0.0.1:1990": 1
           }
       }
   }'
   ```
   
   4. Test route (upstream default response data is the requested uri)
   
   ```shell
   curl http://127.0.0.1:9080/hello -i
   HTTP/1.1 200 OK
   Content-Type: application/octet-stream
   Transfer-Encoding: chunked
   Connection: keep-alive
   Date: Thu, 25 Mar 2021 16:05:58 GMT
   Server: APISIX/2.4
   Access-Control-Allow-Origin: *
   Access-Control-Allow-Methods: *
   Access-Control-Max-Age: 5
   Access-Control-Expose-Headers: *
   Access-Control-Allow-Headers: *
   
   request_uri: /hello
   ```
   
   The `proxy-rewrite` plug-in rewriting uri is not effective.
   
   `access.log` information:
   
   ```
   [warn] 2707#2707: *62368 [lua] proxy-rewrite.lua:182: phase_func(): 
upstream_uri: /route01, client: 127.0.0.1,
   ```
   
   5. Remove the log of `ctx.var.upstream_uri` in the global plugin `cors`
   
   ```shell
   diff --git a/apisix/plugins/proxy-rewrite.lua 
b/apisix/plugins/proxy-rewrite.lua
   index c678b59..e0c3d58 100644
   --- a/apisix/plugins/proxy-rewrite.lua
   +++ b/apisix/plugins/proxy-rewrite.lua
   @@ -179,6 +179,7 @@ function _M.rewrite(conf, ctx)
        end
    
        if not conf.headers then
   +        core.log.warn("upstream_uri: ", ctx.var.upstream_uri)
            return
        end
   ```
   
   6. Test the route again (the upstream default response data is the requested 
uri)
   
   ```shell
   $ curl http://127.0.0.1:9080/hello -i
   HTTP/1.1 200 OK
   Content-Type: application/octet-stream
   Transfer-Encoding: chunked
   Connection: keep-alive
   Date: Thu, 25 Mar 2021 16:13:31 GMT
   Server: APISIX/2.4
   Access-Control-Allow-Origin: *
   Access-Control-Allow-Methods: *
   Access-Control-Max-Age: 5
   Access-Control-Expose-Headers: *
   Access-Control-Allow-Headers: *
   
   request_uri: /route01
   ```
   The `proxy-rewrite` plug-in rewrites the uri to take effect.
   
   `access.log` information:
   
   ```
   [warn] 2707#2707: *62368 [lua] proxy-rewrite.lua:182: phase_func(): 
upstream_uri: /route01, client: 127.0.0.1,
   ```


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

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


Reply via email to