Skip to content

fix: no trailing "?" for empty query table #289

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

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions lib/resty/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ local function _format_request(self, params)

local query = params.query or ""
if type(query) == "table" then
query = "?" .. ngx_encode_args(query)
elseif query ~= "" and str_sub(query, 1, 1) ~= "?" then
query = ngx_encode_args(query)
end
if query ~= "" and str_sub(query, 1, 1) ~= "?" then
query = "?" .. query
end

Expand Down
42 changes: 42 additions & 0 deletions t/01-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,45 @@ GET /a
--- no_error_log
[error]
[warn]



=== TEST 14: Empty query
--- http_config eval: $::HttpConfig
--- config
location = /a {
content_by_lua '
local http = require "resty.http"
local httpc = http.new()
httpc:connect{
scheme = "http",
host = "127.0.0.1",
port = ngx.var.server_port
}

local res, err = httpc:request{
query = {},
path = "/b"
}

ngx.status = res.status

ngx.print(ngx.header.test)

httpc:close()
';
}
location = /b {
content_by_lua '
ngx.header.test = ngx.var.request_uri
';
}
--- request
GET /a
--- response_headers
/b
--- no_error_log
[error]
[warn]