Skip to content
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
6 changes: 4 additions & 2 deletions lib/resty/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ 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]