Skip to content

Commit 08183ea

Browse files
matt-wayronag
andauthoredNov 30, 2023
fix: Added support for inline URL username:password proxy auth (#2473)
* added support for inline URL username:password * Update lib/proxy-agent.js --------- Co-authored-by: Robert Nagy <ronagy@icloud.com>
1 parent 28759f4 commit 08183ea

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎lib/proxy-agent.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,20 @@ class ProxyAgent extends DispatcherBase {
6565
this[kProxyTls] = opts.proxyTls
6666
this[kProxyHeaders] = opts.headers || {}
6767

68+
const resolvedUrl = new URL(opts.uri)
69+
const { origin, port, host, username, password } = resolvedUrl
70+
6871
if (opts.auth && opts.token) {
6972
throw new InvalidArgumentError('opts.auth cannot be used in combination with opts.token')
7073
} else if (opts.auth) {
7174
/* @deprecated in favour of opts.token */
7275
this[kProxyHeaders]['proxy-authorization'] = `Basic ${opts.auth}`
7376
} else if (opts.token) {
7477
this[kProxyHeaders]['proxy-authorization'] = opts.token
78+
} else if (username && password) {
79+
this[kProxyHeaders]['proxy-authorization'] = `Basic ${Buffer.from(`${decodeURIComponent(username)}:${decodeURIComponent(password)}`).toString('base64')}`
7580
}
7681

77-
const resolvedUrl = new URL(opts.uri)
78-
const { origin, port, host } = resolvedUrl
79-
8082
const connect = buildConnector({ ...opts.proxyTls })
8183
this[kConnectEndpoint] = buildConnector({ ...opts.requestTls })
8284
this[kClient] = clientFactory(resolvedUrl, { connect })
@@ -100,7 +102,7 @@ class ProxyAgent extends DispatcherBase {
100102
})
101103
if (statusCode !== 200) {
102104
socket.on('error', () => {}).destroy()
103-
callback(new RequestAbortedError('Proxy response !== 200 when HTTP Tunneling'))
105+
callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`))
104106
}
105107
if (opts.protocol !== 'https:') {
106108
callback(null, socket)

1 commit comments

Comments
 (1)

PandaWorker commented on Dec 24, 2023

@PandaWorker

Thank you <3

Please sign in to comment.