httpclient: handle redirects more graceful
This commit is contained in:
parent
6aa6fb88ab
commit
2c7a30708d
1 changed files with 10 additions and 5 deletions
|
@ -223,7 +223,9 @@ function request_raw(uri, options)
|
||||||
return nil, -3, "invalid response magic: " .. line
|
return nil, -3, "invalid response magic: " .. line
|
||||||
end
|
end
|
||||||
|
|
||||||
local response = {status = line, headers = {}, code = 0, cookies = {}}
|
local response = {
|
||||||
|
status = line, headers = {}, code = 0, cookies = {}, uri = uri
|
||||||
|
}
|
||||||
|
|
||||||
line = linesrc()
|
line = linesrc()
|
||||||
while line and line ~= "" do
|
while line and line ~= "" do
|
||||||
|
@ -292,15 +294,18 @@ function request_raw(uri, options)
|
||||||
if response.code and options.depth > 0 then
|
if response.code and options.depth > 0 then
|
||||||
if response.code == 301 or response.code == 302 or response.code == 307
|
if response.code == 301 or response.code == 302 or response.code == 307
|
||||||
and response.headers.Location then
|
and response.headers.Location then
|
||||||
local nexturi = response.headers.Location
|
local nuri = response.headers.Location or response.headers.location
|
||||||
if not nexturi:find("https?://") then
|
if not nuri then
|
||||||
nexturi = pr .. "://" .. host .. ":" .. port .. nexturi
|
return nil, -5, "invalid reference"
|
||||||
|
end
|
||||||
|
if not nuri:find("https?://") then
|
||||||
|
nuri = pr .. "://" .. host .. ":" .. port .. nuri
|
||||||
end
|
end
|
||||||
|
|
||||||
options.depth = options.depth - 1
|
options.depth = options.depth - 1
|
||||||
sock:close()
|
sock:close()
|
||||||
|
|
||||||
return request_raw(nexturi, options)
|
return request_raw(nuri, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue