Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 16, 2019 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/be6f48bea57fe33a62d4ffd6f0bfcda4 to your computer and use it in GitHub Desktop.
Save isaacs/be6f48bea57fe33a62d4ffd6f0bfcda4 to your computer and use it in GitHub Desktop.
diff --git a/agent.js b/agent.js
index 12ea1ea..81dbdff 100644
--- a/agent.js
+++ b/agent.js
@@ -142,7 +142,9 @@ function getProxyUri (uri, opts) {
}
const getAuth = u =>
- u.username && u.password ? `${u.username}:${u.password}` : null
+ u.username && u.password ? `${u.username}:${u.password}`
+ : u.username ? u.username
+ : null
const getPath = u => u.pathname + u.search + u.hash
diff --git a/test/agent.js b/test/agent.js
index af0c640..75c9c26 100644
--- a/test/agent.js
+++ b/test/agent.js
@@ -125,6 +125,29 @@ test('all expected options passed down to proxy agent', t => {
t.done()
})
+test('all expected options passed down to proxy agent, username only', t => {
+ const opts = Object.assign({
+ proxy: 'https://user-no-pass@my.proxy:1234/foo'
+ // bust the cache
+ }, { ...OPTS, timeout: OPTS.timeout + 1 })
+ t.deepEqual(agent('https://foo.com/bar', opts), {
+ __type: 'https-proxy',
+ host: 'my.proxy',
+ port: '1234',
+ protocol: 'https:',
+ path: '/foo',
+ auth: 'user-no-pass',
+ ca: 'ca',
+ cert: 'cert',
+ key: 'key',
+ maxSockets: 5,
+ localAddress: 'localAddress',
+ rejectUnauthorized: 'strictSSL',
+ timeout: 7
+ }, 'only expected options passed to https proxy')
+ t.done()
+})
+
test('get proxy uri', t => {
const { getProxyUri } = agent
const { httpProxy, httpsProxy, noProxy } = process.env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment