kingmouse-yx opened a new issue, #6993:
URL: https://github.com/apache/apisix/issues/6993

   ### Description
   
   I have a requirement now. I need to parse some data in the request body, 
splice it behind the URL, and then forward it to the upstream.
   Original request:
   url:`http://192.168.2.11:9080/userinfo`
   body:
   ```json
   {
        "userId":"12345",
        "type":"01"
   }
   ```
   
   final request:
   `http://192.168.2.11:9080/userinfo?userId=12345&type=01`
   
   This seems to be a very simple requirement, so I get the message in the 
rewrite phase and use gx.req.set_uri_args.
   Part code:
   
   ```lua
   local req_body_json = core.json.decode(req_body)
   ngx.req.set_uri_args(req_body_json)
   
   ```
   This test is completely OK. It can really meet this requirement. But I found 
that if the proxy rewrite is enabled (modify the path or modify the request 
method, etc.), the request to the downstream URL is an error. The data in the 
body is not spliced behind the url. This can be seen through the log.
   I checked the implementation logic of the proxy rewrite. I found that in the 
proxy rewrite, it is by modifying ctx.var.upstream_ uri to modify the url.
   
   So I made a judgment in my code, as follows:
   
   ```lua
   local req_body_json = core.json.decode(req_body)
   ngx.req.set_uri_args(req_body_json)
   
   local ctx_uri = ctx.var.upstream_uri;
   if ctx_uri and #ctx_uri > 0 then
       ctx.var.upstream_uri = ctx_uri .. '?' .. ctx.var.args
   end
   ```
   
   After this processing, this requirement can be realized whether the proxy 
rewrite is enabled or not.
   But I don't quite understand why apisix handles it in this way. I think 
ngx.req.set_uri_args is more convenient
   
   ### Environment
   
   - APISIX version (run `apisix version`): 2.13.0-alpine
   - Operating system (run `uname -a`): Darwin kingmouse.local 21.4.0 Darwin 
Kernel Version 21.4.0: Mon Feb 21 20:36:53 PST 2022; 
root:xnu-8020.101.4~2/RELEASE_ARM64_T8101 arm64
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): 
openresty/1.19.3.1
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`): 3.4.0
   - APISIX Dashboard version, if relevant: 2.10.1
   - 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