Implement proxy support (configurable). Ref #86.
This commit is contained in:
parent
2f57dd1b2a
commit
50d2637b04
4 changed files with 41 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||
# BSD License. Look at license.txt for more info.
|
||||
import parsecfg, streams, strutils, os, tables
|
||||
import parsecfg, streams, strutils, os, tables, Uri
|
||||
|
||||
import tools, version, nimbletypes
|
||||
|
||||
|
|
@ -10,6 +10,7 @@ type
|
|||
chcp*: bool # Whether to change the code page in .cmd files on Win.
|
||||
packageLists*: Table[string, PackageList] ## URLs to packages.json files
|
||||
cloneUsingHttps*: bool # Whether to replace git:// for https://
|
||||
httpProxy*: Uri # Proxy for package list downloads.
|
||||
|
||||
PackageList* = object
|
||||
name*: string
|
||||
|
|
@ -21,6 +22,8 @@ proc initConfig(): Config =
|
|||
else:
|
||||
result.nimbleDir = getHomeDir() / ".babel"
|
||||
|
||||
result.httpProxy = initUri()
|
||||
|
||||
result.chcp = true
|
||||
result.cloneUsingHttps = true
|
||||
|
||||
|
|
@ -83,6 +86,8 @@ proc parseConfig*(): Config =
|
|||
result.chcp = parseBool(e.value)
|
||||
of "cloneusinghttps":
|
||||
result.cloneUsingHttps = parseBool(e.value)
|
||||
of "httpproxy":
|
||||
result.httpProxy = parseUri(e.value)
|
||||
of "name":
|
||||
case currentSection.normalize
|
||||
of "packagelist":
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||
# BSD License. Look at license.txt for more info.
|
||||
|
||||
import json, strutils, os, parseopt, strtabs
|
||||
import json, strutils, os, parseopt, strtabs, uri
|
||||
from httpclient import Proxy, newProxy
|
||||
|
||||
import nimblepkg/config, nimblepkg/version,
|
||||
nimblepkg/tools
|
||||
|
|
@ -295,3 +296,22 @@ proc parseCmdLine*(): Options =
|
|||
# Rename deprecated babel dir.
|
||||
renameBabelToNimble(result)
|
||||
|
||||
proc getProxy*(options: Options): Proxy =
|
||||
## Returns ``nil`` if no proxy is specified.
|
||||
var url = initUri()
|
||||
if ($options.config.httpProxy).len > 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue