@@ -65,18 +65,20 @@ class ProxyAgent extends DispatcherBase {
65
65
this [ kProxyTls ] = opts . proxyTls
66
66
this [ kProxyHeaders ] = opts . headers || { }
67
67
68
+ const resolvedUrl = new URL ( opts . uri )
69
+ const { origin, port, host, username, password } = resolvedUrl
70
+
68
71
if ( opts . auth && opts . token ) {
69
72
throw new InvalidArgumentError ( 'opts.auth cannot be used in combination with opts.token' )
70
73
} else if ( opts . auth ) {
71
74
/* @deprecated in favour of opts.token */
72
75
this [ kProxyHeaders ] [ 'proxy-authorization' ] = `Basic ${ opts . auth } `
73
76
} else if ( opts . token ) {
74
77
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' ) } `
75
80
}
76
81
77
- const resolvedUrl = new URL ( opts . uri )
78
- const { origin, port, host } = resolvedUrl
79
-
80
82
const connect = buildConnector ( { ...opts . proxyTls } )
81
83
this [ kConnectEndpoint ] = buildConnector ( { ...opts . requestTls } )
82
84
this [ kClient ] = clientFactory ( resolvedUrl , { connect } )
@@ -100,7 +102,7 @@ class ProxyAgent extends DispatcherBase {
100
102
} )
101
103
if ( statusCode !== 200 ) {
102
104
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` ) )
104
106
}
105
107
if ( opts . protocol !== 'https:' ) {
106
108
callback ( null , socket )
1 commit comments
PandaWorker commentedon Dec 24, 2023
Thank you <3