@@ -14,7 +14,7 @@ import {
14
14
getUri ,
15
15
protocols as gProtocols ,
16
16
ProtocolOpts as GetUriOptions ,
17
- } from " get-uri" ;
17
+ } from ' get-uri' ;
18
18
import {
19
19
createPacResolver ,
20
20
FindProxyForURL ,
@@ -28,8 +28,8 @@ type Protocols = keyof typeof gProtocols;
28
28
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29
29
type Protocol < T > = T extends `pac+${infer P } :${infer _ } `
30
30
? P
31
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
- : T extends `${infer P } :${infer _ } `
31
+ : // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ T extends `${infer P } :${infer _ } `
33
33
? P
34
34
: never ;
35
35
@@ -55,11 +55,11 @@ export type PacProxyAgentOptions<T> = PacResolverOptions &
55
55
*/
56
56
export class PacProxyAgent < Uri extends string > extends Agent {
57
57
static readonly protocols : `pac-${Protocols } `[ ] = [
58
- " pac-data" ,
59
- " pac-file" ,
60
- " pac-ftp" ,
61
- " pac-http" ,
62
- " pac-https" ,
58
+ ' pac-data' ,
59
+ ' pac-file' ,
60
+ ' pac-ftp' ,
61
+ ' pac-http' ,
62
+ ' pac-https' ,
63
63
] ;
64
64
65
65
uri : URL ;
@@ -73,16 +73,16 @@ export class PacProxyAgent<Uri extends string> extends Agent {
73
73
super ( ) ;
74
74
75
75
// Strip the "pac+" prefix
76
- const uriStr = typeof uri === " string" ? uri : uri . href ;
77
- this . uri = new URL ( uriStr . replace ( / ^ p a c \+ / i, "" ) ) ;
76
+ const uriStr = typeof uri === ' string' ? uri : uri . href ;
77
+ this . uri = new URL ( uriStr . replace ( / ^ p a c \+ / i, '' ) ) ;
78
78
79
- debug ( " Creating PacProxyAgent with URI %o" , this . uri . href ) ;
79
+ debug ( ' Creating PacProxyAgent with URI %o' , this . uri . href ) ;
80
80
81
81
// @ts -expect-error Not sure why TS is complaining here…
82
82
this . opts = { ...opts } ;
83
83
this . cache = undefined ;
84
84
this . resolver = undefined ;
85
- this . resolverHash = "" ;
85
+ this . resolverHash = '' ;
86
86
this . resolverPromise = undefined ;
87
87
88
88
// For `PacResolver`
@@ -118,17 +118,17 @@ export class PacProxyAgent<Uri extends string> extends Agent {
118
118
const code = await this . loadPacFile ( ) ;
119
119
120
120
// Create a sha1 hash of the JS code
121
- const hash = crypto . createHash ( " sha1" ) . update ( code ) . digest ( " hex" ) ;
121
+ const hash = crypto . createHash ( ' sha1' ) . update ( code ) . digest ( ' hex' ) ;
122
122
123
123
if ( this . resolver && this . resolverHash === hash ) {
124
124
debug (
125
- " Same sha1 hash for code - contents have not changed, reusing previous proxy resolver"
125
+ ' Same sha1 hash for code - contents have not changed, reusing previous proxy resolver'
126
126
) ;
127
127
return this . resolver ;
128
128
}
129
129
130
130
// Cache the resolver
131
- debug ( " Creating new proxy resolver instance" ) ;
131
+ debug ( ' Creating new proxy resolver instance' ) ;
132
132
this . resolver = createPacResolver ( code , this . opts ) ;
133
133
134
134
// Store that sha1 hash for future comparison purposes
@@ -138,10 +138,10 @@ export class PacProxyAgent<Uri extends string> extends Agent {
138
138
} catch ( err : unknown ) {
139
139
if (
140
140
this . resolver &&
141
- ( err as NodeJS . ErrnoException ) . code === " ENOTMODIFIED"
141
+ ( err as NodeJS . ErrnoException ) . code === ' ENOTMODIFIED'
142
142
) {
143
143
debug (
144
- " Got ENOTMODIFIED response, reusing previous proxy resolver"
144
+ ' Got ENOTMODIFIED response, reusing previous proxy resolver'
145
145
) ;
146
146
return this . resolver ;
147
147
}
@@ -155,16 +155,16 @@ export class PacProxyAgent<Uri extends string> extends Agent {
155
155
* @api private
156
156
*/
157
157
private async loadPacFile ( ) : Promise < string > {
158
- debug ( " Loading PAC file: %o" , this . uri ) ;
158
+ debug ( ' Loading PAC file: %o' , this . uri ) ;
159
159
160
160
const rs = await getUri ( this . uri , { ...this . opts , cache : this . cache } ) ;
161
- debug ( " Got `Readable` instance for URI" ) ;
161
+ debug ( ' Got `Readable` instance for URI' ) ;
162
162
this . cache = rs ;
163
163
164
164
const buf = await toBuffer ( rs ) ;
165
- debug ( " Read %o byte PAC file from URI" , buf . length ) ;
165
+ debug ( ' Read %o byte PAC file from URI' , buf . length ) ;
166
166
167
- return buf . toString ( " utf8" ) ;
167
+ return buf . toString ( ' utf8' ) ;
168
168
}
169
169
170
170
/**
@@ -184,15 +184,15 @@ export class PacProxyAgent<Uri extends string> extends Agent {
184
184
const defaultPort = secureEndpoint ? 443 : 80 ;
185
185
let path = req . path ;
186
186
let search : string | null = null ;
187
- const firstQuestion = path . indexOf ( "?" ) ;
187
+ const firstQuestion = path . indexOf ( '?' ) ;
188
188
if ( firstQuestion !== - 1 ) {
189
189
search = path . substring ( firstQuestion ) ;
190
190
path = path . substring ( 0 , firstQuestion ) ;
191
191
}
192
192
193
193
const urlOpts = {
194
194
...opts ,
195
- protocol : secureEndpoint ? " https:" : " http:" ,
195
+ protocol : secureEndpoint ? ' https:' : ' http:' ,
196
196
pathname : path ,
197
197
search,
198
198
@@ -206,47 +206,47 @@ export class PacProxyAgent<Uri extends string> extends Agent {
206
206
} ;
207
207
const url = format ( urlOpts ) ;
208
208
209
- debug ( " url: %o" , url ) ;
209
+ debug ( ' url: %o' , url ) ;
210
210
let result = await resolver ( url ) ;
211
211
212
212
// Default to "DIRECT" if a falsey value was returned (or nothing)
213
213
if ( ! result ) {
214
- result = " DIRECT" ;
214
+ result = ' DIRECT' ;
215
215
}
216
216
217
217
const proxies = String ( result )
218
218
. trim ( )
219
219
. split ( / \s * ; \s * / g)
220
220
. filter ( Boolean ) ;
221
221
222
- if ( this . opts . fallbackToDirect && ! proxies . includes ( " DIRECT" ) ) {
223
- proxies . push ( " DIRECT" ) ;
222
+ if ( this . opts . fallbackToDirect && ! proxies . includes ( ' DIRECT' ) ) {
223
+ proxies . push ( ' DIRECT' ) ;
224
224
}
225
225
226
226
for ( const proxy of proxies ) {
227
227
let agent : Agent | null = null ;
228
228
let socket : net . Socket | null = null ;
229
229
const [ type , target ] = proxy . split ( / \s + / ) ;
230
- debug ( " Attempting to use proxy: %o" , proxy ) ;
230
+ debug ( ' Attempting to use proxy: %o' , proxy ) ;
231
231
232
- if ( type === " DIRECT" ) {
232
+ if ( type === ' DIRECT' ) {
233
233
// Direct connection to the destination endpoint
234
234
socket = secureEndpoint ? tls . connect ( opts ) : net . connect ( opts ) ;
235
- } else if ( type === " SOCKS" || type === " SOCKS5" ) {
235
+ } else if ( type === ' SOCKS' || type === ' SOCKS5' ) {
236
236
// Use a SOCKSv5h proxy
237
237
agent = new SocksProxyAgent ( `socks://${ target } ` , this . opts ) ;
238
- } else if ( type === " SOCKS4" ) {
238
+ } else if ( type === ' SOCKS4' ) {
239
239
// Use a SOCKSv4a proxy
240
240
agent = new SocksProxyAgent ( `socks4a://${ target } ` , this . opts ) ;
241
241
} else if (
242
- type === " PROXY" ||
243
- type === " HTTP" ||
244
- type === " HTTPS"
242
+ type === ' PROXY' ||
243
+ type === ' HTTP' ||
244
+ type === ' HTTPS'
245
245
) {
246
246
// Use an HTTP or HTTPS proxy
247
247
// http://dev.chromium.org/developers/design-documents/secure-web-proxy
248
248
const proxyURL = `${
249
- type === " HTTPS" ? " https" : " http"
249
+ type === ' HTTPS' ? ' https' : ' http'
250
250
} ://${ target } `;
251
251
if ( secureEndpoint ) {
252
252
agent = new HttpsProxyAgent ( proxyURL , this . opts ) ;
@@ -258,24 +258,24 @@ export class PacProxyAgent<Uri extends string> extends Agent {
258
258
try {
259
259
if ( socket ) {
260
260
// "DIRECT" connection, wait for connection confirmation
261
- await once ( socket , " connect" ) ;
262
- req . emit ( " proxy" , { proxy, socket } ) ;
261
+ await once ( socket , ' connect' ) ;
262
+ req . emit ( ' proxy' , { proxy, socket } ) ;
263
263
return socket ;
264
264
}
265
265
if ( agent ) {
266
266
const s = await agent . connect ( req , opts ) ;
267
267
if ( ! ( s instanceof net . Socket ) ) {
268
268
throw new Error (
269
- " Expected a `net.Socket` to be returned from agent"
269
+ ' Expected a `net.Socket` to be returned from agent'
270
270
) ;
271
271
}
272
- req . emit ( " proxy" , { proxy, socket : s } ) ;
272
+ req . emit ( ' proxy' , { proxy, socket : s } ) ;
273
273
return s ;
274
274
}
275
275
throw new Error ( `Could not determine proxy type for: ${ proxy } ` ) ;
276
276
} catch ( err ) {
277
- debug ( " Got error for proxy %o: %o" , proxy , err ) ;
278
- req . emit ( " proxy" , { proxy, error : err } ) ;
277
+ debug ( ' Got error for proxy %o: %o' , proxy , err ) ;
278
+ req . emit ( ' proxy' , { proxy, error : err } ) ;
279
279
}
280
280
}
281
281
@@ -285,4 +285,4 @@ export class PacProxyAgent<Uri extends string> extends Agent {
285
285
) } `
286
286
) ;
287
287
}
288
- }
288
+ }
0 commit comments