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

   ### Current Behavior
   
   when i use go runner to write rewrite plugin, if i did't return new args, 
the original args will lost.
   Example:
   http://example.org/api/test?x=1&y=2 use go-plugin-runner rewrite the path to 
/api/test2 the questring args x,y will lost.
   
   ### Expected Behavior
   
   expect the querystring args operate like the lua proxy-rewrite plugin 
process args. combine the original querystring to rewrited upstream.
   var.upstream_uri = path + args...
   
   maybe modify the code logic ext-plugin/init.lua could fix it. 
   now code logic
   ```
               local len = rewrite:ArgsLength()
               if len > 0 then
                   local changed = {}
                   for i = 1, len do
                       local entry = rewrite:Args(i)
                       local name = entry:Name()
                       local value = entry:Value()
                       if value == nil then
                           args[name] = nil
   
                       else
                           if changed[name] then
                               if type(args[name]) == "table" then
                                   core.table.insert(args[name], value)
                               else
                                   args[name] = {args[name], entry:Value()}
                               end
                           else
                               args[name] = entry:Value()
                           end
   
                           changed[name] = true
                       end
                   end
   
                   core.request.set_uri_args(ctx, args)
   
                   if path then
                       var.upstream_uri = path .. '?' .. var.args
                   end
               end
   ```
   modify logic, chang the combine path and args to `if` outline:
    ```
    local len = rewrite:ArgsLength()
               if len > 0 then
                   local changed = {}
                   for i = 1, len do
                       local entry = rewrite:Args(i)
                       local name = entry:Name()
                       local value = entry:Value()
                       if value == nil then
                           args[name] = nil
   
                       else
                           if changed[name] then
                               if type(args[name]) == "table" then
                                   core.table.insert(args[name], value)
                               else
                                   args[name] = {args[name], entry:Value()}
                               end
                           else
                               args[name] = entry:Value()
                           end
   
                           changed[name] = true
                       end
                   end
               end
               core.request.set_uri_args(ctx, args)
   
               if path then
                       var.upstream_uri = path .. '?' .. var.args
               end
   ```
   
   ### Error Logs
   
   _No response_
   
   ### Steps to Reproduce
   
   1. write a go plugin, use RequestFilter rewrite the request path
   2. the upstream can't recevie args, the args will lost
   3. example like https://example.org/api/test?x=1&y=2  the plugin rewrite the 
path r.SetPath([]byte("/api/test2"))
   
   ### Environment
   
   - APISIX version (run `apisix version`):
   - 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: notifications-unsubscr...@apisix.apache.org.apache.org

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

Reply via email to