From 902526f3c135c02b840f8cf5ef1a900d5d7a3956 Mon Sep 17 00:00:00 2001 From: Adeel Date: Thu, 8 Jan 2015 03:22:47 +0200 Subject: [PATCH] Install: Improves code to get proxy. * Credit: @xzyfer. * Addresses #588. --- scripts/install.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/install.js b/scripts/install.js index a94d2e5b4..5cf50503b 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -43,16 +43,11 @@ function download(url, dest, cb) { */ function getProxy() { - var result; - - ['https-proxy', 'proxy', 'http-proxy'].map(function(config) { + var result = ['https-proxy', 'proxy', 'http-proxy'].filter(function(config) { var proxy = exec('npm config get ' + config, {silent: true}); var output = proxy.output.trim(); - if (proxy.code === 0 && output !== 'undefined' && output !== 'null') { - result = proxy.output; - return; - } + return proxy.code === 0 && validateProxy(output); }); if (result) { @@ -63,6 +58,19 @@ function getProxy() { return env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy; } +/** + * Validates Proxy URL + * + * @param {String} url + * @api private + */ + +function getProxy(url) { + return output !== 'undefined' && + output !== 'null' && + url === require('url').parse(url); +} + /** * Check if binaries exists *