From 9c68105053898e2c3fe0876dcd4472dfeb5489c7 Mon Sep 17 00:00:00 2001 From: Daniel Moore Date: Fri, 1 Dec 2017 19:10:07 -0500 Subject: [PATCH] fix: respect NO_PROXY environment variable (#667) --- lib/index.js | 3 ++- package.json | 1 + test/integration/params-validations-test.js | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 91ca80f5..74af1ca1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,7 @@ 'use strict' var HttpsProxyAgent = require('https-proxy-agent') +var getProxyForUrl = require('proxy-from-env').getProxyForUrl var toCamelCase = require('lodash/camelCase') var urlTemplate = require('url-template') @@ -619,7 +620,7 @@ var Client = module.exports = function (config) { if (this.config.proxy !== undefined) { proxyUrl = this.config.proxy } else { - proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY + proxyUrl = getProxyForUrl(url) } // proxy options will be removed: https://github.com/octokit/node-github/issues/656 diff --git a/package.json b/package.json index a401e710..b03b65f9 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dotenv": "^4.0.0", "https-proxy-agent": "^2.1.0", "lodash": "^4.17.4", + "proxy-from-env": "^1.0.0", "url-template": "^2.0.8" }, "devDependencies": { diff --git a/test/integration/params-validations-test.js b/test/integration/params-validations-test.js index 1536c03b..a97f66d6 100644 --- a/test/integration/params-validations-test.js +++ b/test/integration/params-validations-test.js @@ -26,7 +26,8 @@ describe('params validations', () => { it('request error', () => { const github = new GitHub({ - host: 'nope' + host: '127.0.0.1', + port: 8 // officially unassigned port. See https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers }) return github.orgs.get({org: 'foo'}) @@ -34,7 +35,7 @@ describe('params validations', () => { .catch(error => { error.toJSON().should.deep.equal({ code: '500', - message: 'getaddrinfo ENOTFOUND nope nope:443', + message: 'connect ECONNREFUSED 127.0.0.1:8', status: 'Internal Server Error' }) })