@@ -3,12 +3,11 @@ import * as url from 'url';
33import * as http from 'http' ;
44import * as https from 'https' ;
55
6- import * as LRU from 'lru-cache' ;
6+ import { LRUCache } from 'lru-cache' ;
77
8- import getHttpsProxyAgent = require ( 'https-proxy-agent' ) ;
8+ import { HttpsProxyAgent } from 'https-proxy-agent' ;
99import { PacProxyAgent } from 'pac-proxy-agent' ;
1010import { SocksProxyAgent } from 'socks-proxy-agent' ;
11- const getSocksProxyAgent = ( opts : any ) => new SocksProxyAgent ( opts ) ;
1211
1312import { isNode } from "../util/util" ;
1413import { getProxySetting , matchesNoProxy , ProxySettingSource } from './proxy-config' ;
@@ -24,25 +23,27 @@ const KeepAliveAgents = isNode
2423 } )
2524 } : { } ;
2625
26+ const buildHttpsProxyAgent = ( href : string , opts ?: any ) => new HttpsProxyAgent ( href , opts ) ;
27+ const buildSocksProxyAgent = ( href : string , opts ?: any ) => new SocksProxyAgent ( href , opts ) ;
28+
2729const ProxyAgentFactoryMap = {
28- 'http:' : getHttpsProxyAgent , // HTTPS here really means 'CONNECT-tunnelled' - it can do either
29- 'https:' : getHttpsProxyAgent ,
30+ 'http:' : buildHttpsProxyAgent , // HTTPS here really means 'CONNECT-tunnelled' - it can do either
31+ 'https:' : buildHttpsProxyAgent ,
3032
3133 'pac+http:' : ( ...args : any ) => new PacProxyAgent ( ...args ) ,
3234 'pac+https:' : ( ...args : any ) => new PacProxyAgent ( ...args ) ,
3335
34- 'socks:' : getSocksProxyAgent ,
35- 'socks4:' : getSocksProxyAgent ,
36- 'socks4a:' : getSocksProxyAgent ,
37- 'socks5:' : getSocksProxyAgent ,
38- 'socks5h:' : getSocksProxyAgent
36+ 'socks:' : buildSocksProxyAgent ,
37+ 'socks4:' : buildSocksProxyAgent ,
38+ 'socks4a:' : buildSocksProxyAgent ,
39+ 'socks5:' : buildSocksProxyAgent ,
40+ 'socks5h:' : buildSocksProxyAgent
3941} as const ;
4042
41- const proxyAgentCache = new LRU < string , http . Agent > ( {
43+ const proxyAgentCache = new LRUCache < string , http . Agent > ( {
4244 max : 20 ,
4345
4446 ttl : 1000 * 60 * 5 , // Drop refs to unused agents after 5 minutes
45- ttlResolution : 1000 * 60 , // Check for expiry once every minute maximum
4647 ttlAutopurge : true , // Actively drop expired agents
4748 updateAgeOnGet : true // Don't drop agents while they're in use
4849} ) ;
@@ -87,18 +88,10 @@ export async function getAgent({
8788 proxySetting . additionalTrustedCAs
8889 ) ;
8990
90- proxyAgentCache . set ( cacheKey , buildProxyAgent ( {
91- href,
92- protocol,
93- auth,
94- hostname,
95- port,
96-
97- ...( trustedCerts
98- ? { ca : trustedCerts }
99- : { }
100- )
101- } ) ) ;
91+ proxyAgentCache . set ( cacheKey , buildProxyAgent (
92+ href ! ,
93+ trustedCerts ? { ca : trustedCerts } : { }
94+ ) ) ;
10295 }
10396
10497 return proxyAgentCache . get ( cacheKey ) ;
0 commit comments