Changeset 4324

Show
Ignore:
Timestamp:
03/12/09 21:14:55 (4 years ago)
Author:
Cyrus
Message:

httpclient: handle redirects more graceful

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/httpclient/luasrc/httpclient.lua

    r4313 r4324  
    224224    end 
    225225     
    226     local response = {status = line, headers = {}, code = 0, cookies = {}} 
     226    local response = { 
     227        status = line, headers = {}, code = 0, cookies = {}, uri = uri 
     228    } 
    227229     
    228230    line = linesrc() 
     
    293295        if response.code == 301 or response.code == 302 or response.code == 307 
    294296         and response.headers.Location then 
    295             local nexturi = response.headers.Location 
    296             if not nexturi:find("https?://") then 
    297                 nexturi = pr .. "://" .. host .. ":" .. port .. nexturi 
     297            local nuri = response.headers.Location or response.headers.location 
     298            if not nuri then 
     299                return nil, -5, "invalid reference" 
     300            end 
     301            if not nuri:find("https?://") then 
     302                nuri = pr .. "://" .. host .. ":" .. port .. nuri 
    298303            end 
    299304             
     
    301306            sock:close() 
    302307             
    303             return request_raw(nexturi, options) 
     308            return request_raw(nuri, options) 
    304309        end 
    305310    end