diff --git a/readme.markdown b/readme.markdown index 4afb915..3cf746f 100644 --- a/readme.markdown +++ b/readme.markdown @@ -306,6 +306,10 @@ You can currently configure the following in this file: * ``cloneUsingHttps`` - Whether to replace any ``git://`` inside URLs with ``https://``. **Default: true** +* ``httpProxy`` - The URL of the proxy to use when downloading package listings. + Nimble will also attempt to read the ``http_proxy`` and ``https_proxy`` + environment variables. + **Default: ""** ## Creating Packages diff --git a/src/nimble.nim b/src/nimble.nim index 2a3d585..41be28c 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -2,7 +2,7 @@ # BSD License. Look at license.txt for more info. import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils, - strtabs, json, algorithm, sets + strtabs, json, algorithm, sets, uri from sequtils import toSeq @@ -66,8 +66,16 @@ proc update(options: Options) = let url = list.urls[i] echo("Trying ", url, "...") let tempPath = options.getNimbleDir() / "packages_temp.json" + + # Grab the proxy + let proxy = getProxy(options) + if not proxy.isNil: + var maskedUrl = proxy.url + if maskedUrl.password.len > 0: maskedUrl.password = "***" + echo("Using proxy ", maskedUrl) + try: - downloadFile(url, tempPath) + downloadFile(url, tempPath, proxy = getProxy(options)) except: if i == 0: + url = options.config.httpProxy + else: + try: + if existsEnv("http_proxy"): + parseUri(getEnv("http_proxy"), url) + elif existsEnv("https_proxy"): + parseUri(getEnv("https_proxy"), url) + except ValueError: + echo("WARNING: Unable to parse proxy from environment: ", + getCurrentExceptionMsg()) + + if ($url).len > 0: + return newProxy($url, url.username & ":" & url.password) + else: + return nil \ No newline at end of file