summaryrefslogtreecommitdiffhomepage
path: root/libs/httpclient/luasrc
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-03-12 20:14:55 +0000
committerSteven Barth <steven@midlink.org>2009-03-12 20:14:55 +0000
commit2c7a30708d2c31da64ab23fc07f44f94c1e8b8d7 (patch)
tree65df9399434146f508a82b6420665c0f30edfa2a /libs/httpclient/luasrc
parent6aa6fb88abd6ff1b39d58572b934ca5b17b8a89b (diff)
httpclient: handle redirects more graceful
Diffstat (limited to 'libs/httpclient/luasrc')
-rw-r--r--libs/httpclient/luasrc/httpclient.lua15
1 files changed, 10 insertions, 5 deletions
diff --git a/libs/httpclient/luasrc/httpclient.lua b/libs/httpclient/luasrc/httpclient.lua
index e75cc0373..4f9559310 100644
--- a/libs/httpclient/luasrc/httpclient.lua
+++ b/libs/httpclient/luasrc/httpclient.lua
@@ -223,7 +223,9 @@ function request_raw(uri, options)
return nil, -3, "invalid response magic: " .. line
end
- local response = {status = line, headers = {}, code = 0, cookies = {}}
+ local response = {
+ status = line, headers = {}, code = 0, cookies = {}, uri = uri
+ }
line = linesrc()
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 == 301 or response.code == 302 or response.code == 307
and response.headers.Location then
- local nexturi = response.headers.Location
- if not nexturi:find("https?://") then
- nexturi = pr .. "://" .. host .. ":" .. port .. nexturi
+ local nuri = response.headers.Location or response.headers.location
+ if not nuri then
+ return nil, -5, "invalid reference"
+ end
+ if not nuri:find("https?://") then
+ nuri = pr .. "://" .. host .. ":" .. port .. nuri
end
options.depth = options.depth - 1
sock:close()
- return request_raw(nexturi, options)
+ return request_raw(nuri, options)
end
end