@@ -381,8 +381,8 @@ function analyzeAndMaybePassThroughTls(
381
381
if ( passthroughList && interceptOnlyList ) {
382
382
throw new Error ( 'Cannot use both tlsPassthrough and tlsInterceptOnly options at the same time.' ) ;
383
383
}
384
- const passThroughHostnames = passthroughList ?. map ( ( { hostname } ) => hostname ) ?? [ ] ;
385
- const interceptOnlyHostnames = interceptOnlyList ?. map ( ( { hostname } ) => hostname ) ;
384
+ const passThroughPatterns = passthroughList ?. map ( ( { hostname } ) => new URLPattern ( `https:// ${ hostname } ` ) ) ?? [ ] ;
385
+ const interceptOnlyPatterns = interceptOnlyList ?. map ( ( { hostname } ) => new URLPattern ( `https:// ${ hostname } ` ) ) ;
386
386
387
387
const tlsConnectionListener = server . listeners ( 'connection' ) [ 0 ] as ( socket : net . Socket ) => { } ;
388
388
server . removeListener ( 'connection' , tlsConnectionListener ) ;
@@ -401,11 +401,11 @@ function analyzeAndMaybePassThroughTls(
401
401
ja3Fingerprint : calculateJa3FromFingerprintData ( helloData . fingerprintData )
402
402
} ;
403
403
404
- if ( shouldPassThrough ( connectHostname , passThroughHostnames , interceptOnlyHostnames ) ) {
404
+ if ( shouldPassThrough ( connectHostname , passThroughPatterns , interceptOnlyPatterns ) ) {
405
405
const upstreamPort = connectPort ? parseInt ( connectPort , 10 ) : undefined ;
406
406
passthroughListener ( socket , connectHostname , upstreamPort ) ;
407
407
return ; // Do not continue with TLS
408
- } else if ( shouldPassThrough ( sniHostname , passThroughHostnames , interceptOnlyHostnames ) ) {
408
+ } else if ( shouldPassThrough ( sniHostname , passThroughPatterns , interceptOnlyPatterns ) ) {
409
409
passthroughListener ( socket , sniHostname ! ) ; // Can't guess the port - not included in SNI
410
410
return ; // Do not continue with TLS
411
411
}
@@ -425,18 +425,18 @@ function analyzeAndMaybePassThroughTls(
425
425
export function shouldPassThrough (
426
426
hostname : string | undefined ,
427
427
// Only one of these two should have values (validated above):
428
- passThroughHostnames : string [ ] ,
429
- interceptOnlyHostnames : string [ ] | undefined
428
+ passThroughPatterns : URLPattern [ ] ,
429
+ interceptOnlyPatterns : URLPattern [ ] | undefined
430
430
) : boolean {
431
431
if ( ! hostname ) return false ;
432
432
433
- if ( interceptOnlyHostnames ) {
434
- return ! interceptOnlyHostnames . some ( ( hn ) =>
435
- new URLPattern ( `https:// ${ hn } ` ) . test ( `https://${ hostname } ` )
433
+ if ( interceptOnlyPatterns ) {
434
+ return ! interceptOnlyPatterns . some ( ( pattern ) =>
435
+ pattern . test ( `https://${ hostname } ` )
436
436
) ;
437
437
}
438
438
439
- return passThroughHostnames . some ( ( hn ) =>
440
- new URLPattern ( `https:// ${ hn } ` ) . test ( `https://${ hostname } ` )
439
+ return passThroughPatterns . some ( ( pattern ) =>
440
+ pattern . test ( `https://${ hostname } ` )
441
441
) ;
442
442
}
0 commit comments