diff options
Diffstat (limited to 'src/http.lua')
| -rw-r--r-- | src/http.lua | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/http.lua b/src/http.lua index 5fb59ce..1dff11a 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -173,8 +173,10 @@ local function adjustrequest(reqt) | |||
| 173 | return nreqt | 173 | return nreqt |
| 174 | end | 174 | end |
| 175 | 175 | ||
| 176 | local function shouldredirect(reqt, code) | 176 | local function shouldredirect(reqt, code, headers) |
| 177 | return (reqt.redirect ~= false) and | 177 | return headers.location and |
| 178 | string.gsub(headers.location, "%s", "") ~= "" and | ||
| 179 | (reqt.redirect ~= false) and | ||
| 178 | (code == 301 or code == 302) and | 180 | (code == 301 or code == 302) and |
| 179 | (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") | 181 | (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") |
| 180 | and (not reqt.nredirects or reqt.nredirects < 5) | 182 | and (not reqt.nredirects or reqt.nredirects < 5) |
| @@ -226,7 +228,7 @@ function trequest(reqt) | |||
| 226 | local code, headers, status | 228 | local code, headers, status |
| 227 | code, status = h:receivestatusline() | 229 | code, status = h:receivestatusline() |
| 228 | headers = h:receiveheaders() | 230 | headers = h:receiveheaders() |
| 229 | if shouldredirect(reqt, code) then | 231 | if shouldredirect(reqt, code, headers) then |
| 230 | h:close() | 232 | h:close() |
| 231 | return tredirect(reqt, headers) | 233 | return tredirect(reqt, headers) |
| 232 | elseif shouldauthorize(reqt, code) then | 234 | elseif shouldauthorize(reqt, code) then |
