diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2011-02-07 19:59:37 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2011-02-07 19:59:37 -0200 |
commit | d4ed388021fda732cb08d95844949457fad9631a (patch) | |
tree | 1a452dde382843aa8552a3e1fa6a08e912183917 | |
parent | 1cd08e36c153f0ed30c657b6ff0e7deb379bba39 (diff) | |
download | luarocks-d4ed388021fda732cb08d95844949457fad9631a.tar.gz luarocks-d4ed388021fda732cb08d95844949457fad9631a.tar.bz2 luarocks-d4ed388021fda732cb08d95844949457fad9631a.zip |
allow http_request to follow redirects hopping from http (LuaSocket) to https (LuaSec) and vice-versa.
-rw-r--r-- | src/luarocks/fs/lua.lua | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index d9e717c1..72e7b022 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -479,8 +479,12 @@ if socket_ok then | |||
479 | 479 | ||
480 | local ltn12 = require("ltn12") | 480 | local ltn12 = require("ltn12") |
481 | local luasec_ok, https = pcall(require, "ssl.https") | 481 | local luasec_ok, https = pcall(require, "ssl.https") |
482 | local redirect_protocols = { | ||
483 | http = http, | ||
484 | https = luasec_ok and https, | ||
485 | } | ||
482 | 486 | ||
483 | local function http_request(url, http) | 487 | local function http_request(url, http, loop_control) |
484 | local proxy = cfg.proxy | 488 | local proxy = cfg.proxy |
485 | local url_arg, proxy_result | 489 | local url_arg, proxy_result |
486 | if proxy then | 490 | if proxy then |
@@ -493,6 +497,23 @@ local function http_request(url, http) | |||
493 | local content, err | 497 | local content, err |
494 | if not res then | 498 | if not res then |
495 | err = status | 499 | err = status |
500 | elseif status == 301 or status == 302 then | ||
501 | local location = headers.location | ||
502 | if location then | ||
503 | local protocol, rest = dir.split_url(location) | ||
504 | if redirect_protocols[protocol] then | ||
505 | if not loop_control then | ||
506 | loop_control = {} | ||
507 | elseif loop_control[location] then | ||
508 | return nil, "Redirection loop -- broken URL?" | ||
509 | end | ||
510 | loop_control[url] = true | ||
511 | return http_request(location, redirect_protocols[protocol], loop_control) | ||
512 | else | ||
513 | return nil, "URL redirected to unsupported protocol - install luasec to get HTTPS support." | ||
514 | end | ||
515 | end | ||
516 | err = line | ||
496 | elseif status ~= 200 then | 517 | elseif status ~= 200 then |
497 | err = line | 518 | err = line |
498 | else | 519 | else |