diff --git a/package.json b/package.json index 9c9677e98..f01338af6 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "decompress-response": "^4.2.0", "duplexer3": "^0.1.4", "get-stream": "^5.0.0", + "https-proxy-agent": "^2.2.1", "lowercase-keys": "^2.0.0", "mimic-response": "^2.0.0", "p-cancelable": "^2.0.0", diff --git a/source/normalize-arguments.ts b/source/normalize-arguments.ts index b2363706e..978c7d5dd 100644 --- a/source/normalize-arguments.ts +++ b/source/normalize-arguments.ts @@ -1,5 +1,6 @@ import urlLib, {URL, URLSearchParams} from 'url'; // TODO: Use the `URL` global when targeting Node.js 10 import CacheableLookup from 'cacheable-lookup'; +import ProxyAgent from 'https-proxy-agent'; import is from '@sindresorhus/is'; import lowercaseKeys from 'lowercase-keys'; import urlToOptions from './utils/url-to-options'; @@ -183,6 +184,11 @@ export const normalizeArguments = (url, options, defaults?: any) => { options.path = `${options.path.split('?')[0]}?${searchParams}`; } + const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || undefined; + if (is.nonEmptyString(proxy)) { + options.agent = new ProxyAgent(proxy); + } + if (options.hostname === 'unix') { const matches = /(.+?):(.+)/.exec(options.path);