From f994a726c346fc1df003debd071a79fa109141f0 Mon Sep 17 00:00:00 2001 From: hisham Date: Tue, 14 Apr 2009 18:46:27 +0000 Subject: use a custom user-agent when communicating git-svn-id: http://luarocks.org/svn/luarocks/trunk@7 9ca3f7c1-7366-0410-b1a3-b5c78f85698c --- src/luarocks/cfg.lua | 2 ++ src/luarocks/fs/lua.lua | 1 + src/luarocks/fs/unix.lua | 7 ++++--- src/luarocks/fs/win32.lua | 5 +++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 3c4c5aed..71efea47 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -240,3 +240,5 @@ if not next(rocks_trees) then table.insert(rocks_trees, LUAROCKS_ROCKS_TREE) end end + +user_agent = "LuaRocks/"..program_version diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 2bc13dae..7d411e49 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -485,6 +485,7 @@ function download(url, filename) ok = ok and c:setopt(curl.OPT_HTTPHEADER, "Connection: Keep-Alive") ok = ok and c:setopt(curl.OPT_URL, url) ok = ok and c:setopt(curl.OPT_CONNECTTIMEOUT, 15) + ok = ok and c:setopt(curl.OPT_USERAGENT, cfg.user_agent) ok = ok and c:perform() ok = ok and c:close() file:close() diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index bc0f4594..1f8411c9 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -281,14 +281,15 @@ function download(url, filename) assert(type(filename) == "string" or not filename) if cfg.downloader == "wget" then + local wget_cmd = "wget --user-agent="..cfg.user_agent.." --quiet --continue " if filename then - return fs_execute("wget --quiet --continue --output-document ", filename, url) + return fs_execute(wget_cmd.." --output-document ", filename, url) else - return fs_execute("wget --quiet --continue ", url) + return fs_execute(wget_cmd, url) end elseif cfg.downloader == "curl" then filename = filename or dir.base_name(url) - return fs_execute_string("curl "..fs_Q(url).." 2> /dev/null 1> "..fs_Q(filename)) + return fs_execute_string("curl --user-agent "..cfg.user_agent.." "..fs_Q(url).." 2> /dev/null 1> "..fs_Q(filename)) end end diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index cafdca7d..da9b7d60 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -223,11 +223,12 @@ end function download(url, filename) assert(type(url) == "string") assert(type(filename) == "string" or not filename) + local wget_cmd = "wget --user-agent="..cfg.user_agent.." --quiet --continue " if filename then - return fs_execute("wget --quiet --continue --output-document ", filename, url) + return fs_execute(wget_cmd.." --output-document ", filename, url) else - return fs_execute("wget --quiet --continue ", url) + return fs_execute(wget_cmd, url) end end -- cgit v1.2.3-55-g6feb