Implement proxy support (configurable). Ref #86.
This commit is contained in:
parent
2f57dd1b2a
commit
50d2637b04
4 changed files with 41 additions and 4 deletions
|
|
@ -306,6 +306,10 @@ You can currently configure the following in this file:
|
||||||
* ``cloneUsingHttps`` - Whether to replace any ``git://`` inside URLs with
|
* ``cloneUsingHttps`` - Whether to replace any ``git://`` inside URLs with
|
||||||
``https://``.
|
``https://``.
|
||||||
**Default: true**
|
**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
|
## Creating Packages
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
# BSD License. Look at license.txt for more info.
|
# BSD License. Look at license.txt for more info.
|
||||||
|
|
||||||
import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils,
|
import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils,
|
||||||
strtabs, json, algorithm, sets
|
strtabs, json, algorithm, sets, uri
|
||||||
|
|
||||||
from sequtils import toSeq
|
from sequtils import toSeq
|
||||||
|
|
||||||
|
|
@ -66,8 +66,16 @@ proc update(options: Options) =
|
||||||
let url = list.urls[i]
|
let url = list.urls[i]
|
||||||
echo("Trying ", url, "...")
|
echo("Trying ", url, "...")
|
||||||
let tempPath = options.getNimbleDir() / "packages_temp.json"
|
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:
|
try:
|
||||||
downloadFile(url, tempPath)
|
downloadFile(url, tempPath, proxy = getProxy(options))
|
||||||
except:
|
except:
|
||||||
if i == <list.urls.len:
|
if i == <list.urls.len:
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (C) Dominik Picheta. All rights reserved.
|
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||||
# BSD License. Look at license.txt for more info.
|
# 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
|
import tools, version, nimbletypes
|
||||||
|
|
||||||
|
|
@ -10,6 +10,7 @@ type
|
||||||
chcp*: bool # Whether to change the code page in .cmd files on Win.
|
chcp*: bool # Whether to change the code page in .cmd files on Win.
|
||||||
packageLists*: Table[string, PackageList] ## URLs to packages.json files
|
packageLists*: Table[string, PackageList] ## URLs to packages.json files
|
||||||
cloneUsingHttps*: bool # Whether to replace git:// for https://
|
cloneUsingHttps*: bool # Whether to replace git:// for https://
|
||||||
|
httpProxy*: Uri # Proxy for package list downloads.
|
||||||
|
|
||||||
PackageList* = object
|
PackageList* = object
|
||||||
name*: string
|
name*: string
|
||||||
|
|
@ -21,6 +22,8 @@ proc initConfig(): Config =
|
||||||
else:
|
else:
|
||||||
result.nimbleDir = getHomeDir() / ".babel"
|
result.nimbleDir = getHomeDir() / ".babel"
|
||||||
|
|
||||||
|
result.httpProxy = initUri()
|
||||||
|
|
||||||
result.chcp = true
|
result.chcp = true
|
||||||
result.cloneUsingHttps = true
|
result.cloneUsingHttps = true
|
||||||
|
|
||||||
|
|
@ -83,6 +86,8 @@ proc parseConfig*(): Config =
|
||||||
result.chcp = parseBool(e.value)
|
result.chcp = parseBool(e.value)
|
||||||
of "cloneusinghttps":
|
of "cloneusinghttps":
|
||||||
result.cloneUsingHttps = parseBool(e.value)
|
result.cloneUsingHttps = parseBool(e.value)
|
||||||
|
of "httpproxy":
|
||||||
|
result.httpProxy = parseUri(e.value)
|
||||||
of "name":
|
of "name":
|
||||||
case currentSection.normalize
|
case currentSection.normalize
|
||||||
of "packagelist":
|
of "packagelist":
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
# Copyright (C) Dominik Picheta. All rights reserved.
|
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||||
# BSD License. Look at license.txt for more info.
|
# 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,
|
import nimblepkg/config, nimblepkg/version,
|
||||||
nimblepkg/tools
|
nimblepkg/tools
|
||||||
|
|
@ -295,3 +296,22 @@ proc parseCmdLine*(): Options =
|
||||||
# Rename deprecated babel dir.
|
# Rename deprecated babel dir.
|
||||||
renameBabelToNimble(result)
|
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