Skip to content
Closed
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
17 changes: 17 additions & 0 deletions lib/resty/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ local str_lower = string.lower
local str_upper = string.upper
local str_find = string.find
local str_sub = string.sub
local str_gsub = string.gsub
local str_match = string.match
local tbl_concat = table.concat
local tbl_insert = table.insert
local ngx_encode_args = ngx.encode_args
Expand Down Expand Up @@ -271,6 +273,21 @@ end
function _M.parse_uri(_, uri, query_in_path)
if query_in_path == nil then query_in_path = true end

do
local prefix, authority, suffix = str_match(uri, "^(.-//)([^/?#]*)(.*)$")
if authority and str_sub(authority, 1, 1) ~= "[" then
local last = str_find(authority, ":[^:]*$")
if last then
local host = str_sub(authority, 1, last - 1)
local port = str_sub(authority, last + 1)
local _, colons = str_gsub(host, ":", "")
if colons > 1 and str_find(port, "^%d+$") and str_find(host, "^[%x:.]+$") then
uri = prefix .. "[" .. host .. "]:" .. port .. suffix
end
end
end
end

local m, err = ngx_re_match(
uri,
[[^(?:(http[s]?):)?//((?:[^\[\]:/\?]+)|(?:\[.+\]))(?::(\d+))?([^\?]*)\??(.*)]],
Expand Down
Loading