Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runloop): query args not forwarded bug #11328

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1389,9 +1389,7 @@ return {
-- We overcome this behavior with our own logic, to preserve user
-- desired semantics.
-- perf: branch usually not taken, don't cache var outside
if byte(ctx.request_uri or var.request_uri, -1) == QUESTION_MARK then
var.upstream_uri = var.upstream_uri .. "?"
elseif var.is_args == "?" then
if byte(ctx.request_uri or var.request_uri, -1) == QUESTION_MARK or var.is_args == "?" then
var.upstream_uri = var.upstream_uri .. "?" .. (var.args or "")
end

Expand Down
69 changes: 69 additions & 0 deletions spec/02-integration/05-proxy/32-query-params_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
local helpers = require "spec.helpers"
local cjson = require "cjson"

for _, strategy in helpers.each_strategy() do
describe("query args specs [#" .. strategy .. "]", function()
local proxy_client

lazy_setup(function()
local bp = helpers.get_db_utils(strategy, {
"plugins",
"routes",
"services",
})

local service = assert(bp.services:insert({
url = helpers.mock_upstream_url
}))

local route = assert(bp.routes:insert({
service = service,
paths = { "/set-query-arg" }
}))

assert(bp.plugins:insert({
name = "request-transformer",
route = { id = route.id },
config = {
add = {
querystring = {"dummy:1"},
},
},
}))

helpers.start_kong({
database = strategy,
plugins = "bundled",
nginx_conf = "spec/fixtures/custom_nginx.template",
})
end)

lazy_teardown(function()
helpers.stop_kong()
end)

before_each(function()
proxy_client = helpers.proxy_client()
end)

after_each(function()
if proxy_client then
proxy_client:close()
end
end)

it("does proxy set query args if URI does not contain arguments", function()
local res = assert(proxy_client:send {
method = "GET",
path = "/set-query-arg?",
headers = {
["Host"] = "mock_upstream",
},
})

local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equal("1", json.uri_args.dummy)
end)
end)
end