From 9dc40793b997a029a1e5c86b790841eb484d1bab Mon Sep 17 00:00:00 2001 From: Pavan Ravipati Date: Tue, 23 Mar 2021 15:24:03 -0700 Subject: [PATCH 1/3] proxyAuth is not set when authentication is not provided --- __tests__/proxy.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/__tests__/proxy.test.ts b/__tests__/proxy.test.ts index e8e79f4..7ba3cef 100644 --- a/__tests__/proxy.test.ts +++ b/__tests__/proxy.test.ts @@ -2,6 +2,7 @@ import * as http from 'http' import * as httpm from '../_out' import * as pm from '../_out/proxy' import * as proxy from 'proxy' +import * as tunnelm from 'tunnel' let _proxyConnects: string[] let _proxyServer: http.Server @@ -195,6 +196,26 @@ describe('proxy', () => { expect(obj.url).toBe('https://httpbin.org/get') expect(_proxyConnects).toHaveLength(0) }) + + it('proxyAuth not set in tunnel agent when authentication is not provided', async () => { + process.env['https_proxy'] = 'http://127.0.0.1:8080' + const httpClient = new httpm.HttpClient() + let agent: tunnelm.TunnelingAgent = httpClient.getAgent('https://some-url') + console.log(agent) + expect(agent.proxyOptions.host).toBe('127.0.0.1') + expect(agent.proxyOptions.port).toBe('8080') + expect(agent.proxyOptions.proxyAuth).toBe(undefined) + }) + + it('proxyAuth is set in tunnel agent when authentication is provided', async () => { + process.env['https_proxy'] = 'http://user:password@127.0.0.1:8080' + const httpClient = new httpm.HttpClient() + let agent: tunnelm.TunnelingAgent = httpClient.getAgent('https://some-url') + console.log(agent) + expect(agent.proxyOptions.host).toBe('127.0.0.1') + expect(agent.proxyOptions.port).toBe('8080') + expect(agent.proxyOptions.proxyAuth).toBe('user:password') + }) }) function _clearVars() { From e3934bd2d3b5e46eddc3537f5382b013b9e7bb89 Mon Sep 17 00:00:00 2001 From: Pavan Ravipati Date: Tue, 23 Mar 2021 15:25:35 -0700 Subject: [PATCH 2/3] Do not configure proxyAuth when no proxy authentication is provided --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 97a3fa4..4dfecde 100644 --- a/index.ts +++ b/index.ts @@ -642,7 +642,7 @@ export class HttpClient { maxSockets: maxSockets, keepAlive: this._keepAlive, proxy: { - proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`, + ...((proxyUrl.username || proxyUrl.password) && { proxyAuth: `${proxyUrl.username}:${proxyUrl.password}` }), host: proxyUrl.hostname, port: proxyUrl.port } From 8815420ebb3e29f2afa261a25c0e93e355fe6394 Mon Sep 17 00:00:00 2001 From: Pavan Ravipati Date: Wed, 24 Mar 2021 14:36:53 -0700 Subject: [PATCH 3/3] Prettify changes Co-authored-by: Felipe Galindo Sanchez --- index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 4dfecde..a7858d9 100644 --- a/index.ts +++ b/index.ts @@ -642,7 +642,9 @@ export class HttpClient { maxSockets: maxSockets, keepAlive: this._keepAlive, proxy: { - ...((proxyUrl.username || proxyUrl.password) && { proxyAuth: `${proxyUrl.username}:${proxyUrl.password}` }), + ...((proxyUrl.username || proxyUrl.password) && { + proxyAuth: `${proxyUrl.username}:${proxyUrl.password}` + }), host: proxyUrl.hostname, port: proxyUrl.port }