@@ -15,7 +15,7 @@ type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
15
15
type ConnectOptsMap = {
16
16
http : Omit < net . TcpNetConnectOpts , 'host' | 'port' > ;
17
17
https : Omit < tls . ConnectionOptions , 'host' | 'port' > ;
18
- }
18
+ } ;
19
19
20
20
type ConnectOpts < T > = {
21
21
[ P in keyof ConnectOptsMap ] : Protocol < T > extends P
@@ -40,7 +40,7 @@ export type HttpsProxyAgentOptions<T> = ConnectOpts<T> & {
40
40
* the connection to the proxy server has been established.
41
41
*/
42
42
export class HttpsProxyAgent < Uri extends string > extends Agent {
43
- static protocols = [ " http" , " https" ] as const ;
43
+ static protocols = [ ' http' , ' https' ] as const ;
44
44
45
45
readonly proxy : URL ;
46
46
proxyHeaders : OutgoingHttpHeaders ;
@@ -52,12 +52,15 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
52
52
53
53
constructor ( proxy : Uri | URL , opts ?: HttpsProxyAgentOptions < Uri > ) {
54
54
super ( ) ;
55
- this . proxy = typeof proxy === " string" ? new URL ( proxy ) : proxy ;
55
+ this . proxy = typeof proxy === ' string' ? new URL ( proxy ) : proxy ;
56
56
this . proxyHeaders = opts ?. headers ?? { } ;
57
- debug ( " Creating new HttpsProxyAgent instance: %o" , this . proxy . href ) ;
57
+ debug ( ' Creating new HttpsProxyAgent instance: %o' , this . proxy . href ) ;
58
58
59
59
// Trim off the brackets from IPv6 addresses
60
- const host = ( this . proxy . hostname || this . proxy . host ) . replace ( / ^ \[ | \] $ / g, '' ) ;
60
+ const host = ( this . proxy . hostname || this . proxy . host ) . replace (
61
+ / ^ \[ | \] $ / g,
62
+ ''
63
+ ) ;
61
64
const port = this . proxy . port
62
65
? parseInt ( this . proxy . port , 10 )
63
66
: this . secureProxy
@@ -89,10 +92,10 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
89
92
// Create a socket connection to the proxy server.
90
93
let socket : net . Socket ;
91
94
if ( secureProxy ) {
92
- debug ( " Creating `tls.Socket`: %o" , this . connectOpts ) ;
95
+ debug ( ' Creating `tls.Socket`: %o' , this . connectOpts ) ;
93
96
socket = tls . connect ( this . connectOpts ) ;
94
97
} else {
95
- debug ( " Creating `net.Socket`: %o" , this . connectOpts ) ;
98
+ debug ( ' Creating `net.Socket`: %o' , this . connectOpts ) ;
96
99
socket = net . connect ( this . connectOpts ) ;
97
100
}
98
101
@@ -105,9 +108,9 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
105
108
const auth = `${ decodeURIComponent (
106
109
proxy . username
107
110
) } :${ decodeURIComponent ( proxy . password ) } `;
108
- headers [ " Proxy-Authorization" ] = `Basic ${ Buffer . from (
111
+ headers [ ' Proxy-Authorization' ] = `Basic ${ Buffer . from (
109
112
auth
110
- ) . toString ( " base64" ) } `;
113
+ ) . toString ( ' base64' ) } `;
111
114
}
112
115
113
116
// The `Host` header should only include the port
@@ -118,7 +121,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
118
121
}
119
122
headers . Host = host ;
120
123
121
- headers . Connection = " close" ;
124
+ headers . Connection = ' close' ;
122
125
for ( const name of Object . keys ( headers ) ) {
123
126
payload += `${ name } : ${ headers [ name ] } \r\n` ;
124
127
}
@@ -130,15 +133,15 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
130
133
const { statusCode, buffered } = await proxyResponsePromise ;
131
134
132
135
if ( statusCode === 200 ) {
133
- req . once ( " socket" , resume ) ;
136
+ req . once ( ' socket' , resume ) ;
134
137
135
138
if ( opts . secureEndpoint ) {
136
139
// The proxy is connecting to a TLS server, so upgrade
137
140
// this socket connection to a TLS connection.
138
- debug ( " Upgrading socket connection to TLS" ) ;
141
+ debug ( ' Upgrading socket connection to TLS' ) ;
139
142
const servername = opts . servername || opts . host ;
140
143
const s = tls . connect ( {
141
- ...omit ( opts , " host" , " path" , " port" ) ,
144
+ ...omit ( opts , ' host' , ' path' , ' port' ) ,
142
145
socket,
143
146
servername,
144
147
} ) ;
@@ -169,9 +172,9 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
169
172
fakeSocket . readable = true ;
170
173
171
174
// Need to wait for the "socket" event to re-play the "data" events.
172
- req . once ( " socket" , ( s : net . Socket ) => {
173
- debug ( " Replaying proxy buffer for failed request" ) ;
174
- assert ( s . listenerCount ( " data" ) > 0 ) ;
175
+ req . once ( ' socket' , ( s : net . Socket ) => {
176
+ debug ( ' Replaying proxy buffer for failed request' ) ;
177
+ assert ( s . listenerCount ( ' data' ) > 0 ) ;
175
178
176
179
// Replay the "buffered" Buffer onto the fake `socket`, since at
177
180
// this point the HTTP module machinery has been hooked up for
0 commit comments