Skip to content

bug: ext-plugin process rewrite:args logic error #12240

Open
@wanglihui

Description

@wanglihui

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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions