in lib/resty/http.lua [835:957]
function _M.request_uri(self, uri, params)
params = tbl_copy(params or {})
local parsed_uri, err = self:parse_uri(uri, false)
if not parsed_uri then
return nil, err
end
local scheme, host, port, path, query = unpack(parsed_uri)
if not params.path then params.path = path end
if not params.query then params.query = query end
local proxy_uri = self:get_proxy_uri(scheme, host)
local c, err
if proxy_uri then
local proxy_authorization
if scheme == "https" then
if params.headers and params.headers["Proxy-Authorization"] then
proxy_authorization = params.headers["Proxy-Authorization"]
else
proxy_authorization = self.proxy_opts.https_proxy_authorization
end
end
c, err = self:connect_proxy(proxy_uri, scheme, host, port, proxy_authorization)
else
c, err = self:connect(host, port)
end
if not c then
return nil, err
end
if proxy_uri then
if scheme == "http" then
if port == 80 then
params.path = scheme .. "://" .. host .. path
else
params.path = scheme .. "://" .. host .. ":" .. port .. path
end
if self.proxy_opts.http_proxy_authorization then
if not params.headers then
params.headers = {}
end
if not params.headers["Proxy-Authorization"] then
params.headers["Proxy-Authorization"] = self.proxy_opts.http_proxy_authorization
end
end
elseif scheme == "https" then
self.keepalive = false
end
self.host = host
self.port = port
end
if scheme == "https" then
local verify = true
if params.ssl_verify == false then
verify = false
end
local ok, err = self:ssl_handshake(nil, host, verify)
if not ok then
self:close()
return nil, err
end
end
local res, err = self:request(params)
if not res then
self:close()
return nil, err
end
local body, err = res:read_body()
if not body then
self:close()
return nil, err
end
res.body = body
if params.keepalive == false then
local ok, err = self:close()
if not ok then
ngx_log(ngx_ERR, err)
end
else
local ok, err = self:set_keepalive(params.keepalive_timeout, params.keepalive_pool)
if not ok then
ngx_log(ngx_ERR, err)
end
end
return res, nil
end