Skip to content

Commit

Permalink
install: support HTTPS_PROXY
Browse files Browse the repository at this point in the history
  • Loading branch information
Winston Liu authored and Winston Liu committed May 14, 2019
1 parent 721eb69 commit 9726745
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 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,24 @@ 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 (url.parse(uri).protocol === 'https:') {
if (!proxyUrl) {
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

0 comments on commit 9726745

Please sign in to comment.