diff options
| author | ruki <[email protected]> | 2020-02-14 23:18:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-14 13:50:33 +0800 |
| commit | c00d159a9a510e39ac5e00cb29c26651f4fc56aa (patch) | |
| tree | 80c0ebc4ace229a7c16e71e7efcf049d41f06157 /xmake/modules/net/http | |
| parent | ffb92f48bcfbe4c34d027a7e01ff27b18b97c431 (diff) | |
add subsystem host andarch
Diffstat (limited to 'xmake/modules/net/http')
| -rw-r--r-- | xmake/modules/net/http/download.lua | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/xmake/modules/net/http/download.lua b/xmake/modules/net/http/download.lua index cf7bda691..6a292c20e 100644 --- a/xmake/modules/net/http/download.lua +++ b/xmake/modules/net/http/download.lua @@ -22,6 +22,35 @@ import("core.base.option") import("lib.detect.find_tool") +-- get user agent +function _get_user_agent() + + -- init user agent + if _g._USER_AGENT == nil then + + -- init systems + local systems = {macosx = "Macintosh", linux = "Linux", windows = "Windows", msys = "MSYS", cygwin = "Cygwin"} + + -- os user agent + local os_user_agent = "" + if is_host("macosx") then + local osver = try { function() return os.iorun("/usr/bin/sw_vers -productVersion") end } + if osver then + os_user_agent = ("Intel Mac OS X " .. (osver or "")):trim() + end + elseif is_host("linux", "msys", "cygwin") then + local osver = try { function () return os.iorun("uname -r") end } + if osver then + os_user_agent = (os_user_agent .. " " .. (osver or "")):trim() + end + end + + -- make user agent + _g._USER_AGENT = string.format("Xmake/%s (%s;%s)", xmake.version(), systems[os.subhost()] or os.subhost(), os_user_agent) + end + return _g._USER_AGENT +end + -- download url using curl function _curl_download(tool, url, outputfile) @@ -34,7 +63,7 @@ function _curl_download(tool, url, outputfile) end -- set user-agent - local user_agent = os.user_agent() + local user_agent = _get_user_agent() if user_agent then if tool.version then user_agent = user_agent .. " curl/" .. tool.version @@ -71,7 +100,7 @@ function _wget_download(tool, url, outputfile) end -- set user-agent - local user_agent = os.user_agent() + local user_agent = _get_user_agent() if user_agent then if tool.version then user_agent = user_agent .. " wget/" .. tool.version |
