Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Some additional resources for addons and writing `gyp` files:
| `--devdir=$path` | SDK download directory (default is OS cache directory)
| `--ensure` | Don't reinstall headers if already present
| `--dist-url=$url` | Download header tarball from custom URL
| `--proxy=$url` | Set HTTP proxy for downloading header tarball
| `--proxy=$url` | Set HTTP(S) proxy for downloading header tarball
| `--cafile=$cafile` | Override default CA chain (to download tarball)
| `--nodedir=$path` | Set the path to the node source code
| `--python=$path` | Set path to the Python 2 binary
Expand Down
27 changes: 20 additions & 7 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var fs = require('graceful-fs')
, os = require('os')
, tar = require('tar')
, path = require('path')
, url = require('url')
, crypto = require('crypto')
, log = require('npmlog')
, semver = require('semver')
Expand Down Expand Up @@ -413,11 +414,11 @@ function install (fs, gyp, argv, callback) {

}

function download (gyp, env, url) {
log.http('GET', url)
function download (gyp, env, uri) {
log.http('GET', uri)

var requestOpts = {
uri: url
uri
, headers: {
'User-Agent': 'node-gyp v' + gyp.version + ' (node ' + process.version + ')'
}
Expand All @@ -429,10 +430,22 @@ function download (gyp, env, url) {
}

// basic support for a proxy server
var proxyUrl = gyp.opts.proxy
|| env.http_proxy
|| env.HTTP_PROXY
|| env.npm_config_proxy
var proxyUrl = gyp.opts.proxy;

// prefer HTTPS proxy if contacting an HTTPS uri
if (!proxyUrl && url.parse(uri).protocol === 'https:') {
proxyUrl = env.https_proxy
|| env.HTTPS_PROXY
|| env.npm_config_https_proxy
}

// but fallback to an HTTP proxy as needed
if (!proxyUrl) {
proxyUrl = env.http_proxy
|| env.HTTP_PROXY
|| env.npm_config_proxy
}

if (proxyUrl) {
if (/^https?:\/\//i.test(proxyUrl)) {
log.verbose('download', 'using proxy url: "%s"', proxyUrl)
Expand Down