@@ -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 )
0 commit comments