HTTP proxies are a fact of life in the corporate universe, and since
we are not always using wget (or curl) anymore, the direct socket
download code must respect any proxy. This patch reads the value of
PROXY that has been set in the per-user or system configuration file
(e.g. ~/.luarocks/config.lua). Note that it does need an explicit
http://, unlike the http_proxy shell variable. (Initially I tried to
read this but sudo processes don't get any variables which were set by
the user.)
This is around line 497, luarocks/fs/lua.lua - this version of
download() will be used if LuaSocket is available.
steve d.
-----------------------------
if socket_ok then
local ltn12 = require 'ltn12'
--- Download a remote file.
-- @param url string: URL to be fetched.
-- @param filename string or nil: this function attempts to detect the
-- resulting local filename of the remote file as the basename of the URL;
-- if that is not correct (due to a redirection, for example), the local
-- filename can be given explicitly as this second argument.
-- @return boolean: true on success, false on failure.
function download(url, filename)
assert(type(url) == "string")
assert(type(filename) == "string" or not filename)
filename = dir.path(fs.current_dir(), filename or dir.base_name(url))
local content, err
if util.starts_with(url, "http:") then
local proxy = cfg.PROXY
local url_arg, result
if proxy then -- construct an explicit HTTP request
result = {}
url_arg = {url = url,proxy=proxy,sink=ltn12.sink.table(result)}
else
url_arg = url
end
local res, status, headers, line = http.request(url_arg)
if not res then
err = status
elseif status ~= 200 then
err = line
else
if result then res = table.concat(result) end -- result is a table
content = res
end
elseif util.starts_with(url, "ftp:") then
content, err = ftp.get(url)
end
if not content then
return false, "Failed downloading: " .. err
end
local file = io.open(filename, "wb")
if not file then return false end
file:write(content)
file:close()
return true
end
end
------------------------------
_______________________________________________
Luarocks-developers mailing list
[email protected]
http://lists.luaforge.net/cgi-bin/mailman/listinfo/luarocks-developers