Skip to content

Commit

Permalink
Fixes #86.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Dec 29, 2015
1 parent 9bc0823 commit 2674cac
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,26 @@ proc parseCmdLine*(): Options =

proc getProxy*(options: Options): Proxy =
## Returns ``nil`` if no proxy is specified.
var url = initUri()
var url = ""
if ($options.config.httpProxy).len > 0:
url = options.config.httpProxy
url = $options.config.httpProxy
else:
try:
if existsEnv("http_proxy"):
parseUri(getEnv("http_proxy"), url)
url = getEnv("http_proxy")
elif existsEnv("https_proxy"):
parseUri(getEnv("https_proxy"), url)
url = getEnv("https_proxy")
except ValueError:
echo("WARNING: Unable to parse proxy from environment: ",
getCurrentExceptionMsg())

if ($url).len > 0:
return newProxy($url, url.username & ":" & url.password)
if url.len > 0:
var parsed = parseUri(url)
if parsed.scheme.len == 0 or parsed.hostname.len == 0:
parsed = parseUri("http://" & url)
let auth =
if parsed.username.len > 0: parsed.username & ":" & parsed.password
else: ""
return newProxy($parsed, auth)
else:
return nil

0 comments on commit 2674cac

Please sign in to comment.