@@ -9,6 +9,22 @@ dns.setServers([
99 '1.1.1.1'
1010] ) ;
1111
12+ const httpAgent = new http . Agent ( {
13+ keepAlive : true ,
14+ keepAliveMsecs : 50 * 1000 ,
15+ } ) ;
16+ const httpsAgent = new https . Agent ( {
17+ keepAlive : true ,
18+ keepAliveMsecs : 50 * 1000 ,
19+ } ) ;
20+ const defaultAgent = function ( _parsedURL ) {
21+ if ( _parsedURL . protocol == 'http:' ) {
22+ return httpAgent ;
23+ } else {
24+ return httpsAgent ;
25+ }
26+ }
27+
1228const server = http . createServer ( ) ;
1329
1430
@@ -92,12 +108,22 @@ server.on('connect', async function (req, socket, head) {
92108 const opts = { host : host , port : port } ;
93109 const uid = uuid . v1 ( ) ;
94110
95- const remmoteRes = await fetch ( CONF . pfx + '/httpsconnect' , {
96- headers : {
97- uid : uid ,
98- 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3756.400 QQBrowser/10.5.4039.400' ,
99- conncfg : Buffer . from ( JSON . stringify ( opts ) ) . toString ( 'base64' )
100- }
111+
112+ const beginConn = ( ) => {
113+ return fetch ( CONF . pfx + '/httpsconnect' , {
114+ headers : {
115+ uid : uid ,
116+ 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3756.400 QQBrowser/10.5.4039.400' ,
117+ conncfg : Buffer . from ( JSON . stringify ( opts ) ) . toString ( 'base64' )
118+ } ,
119+ agent : defaultAgent
120+ } )
121+ }
122+
123+ const remmoteRes = await beginConn ( ) . catch ( ( ) => {
124+ return beginConn ( )
125+ } ) . catch ( ( ) => {
126+ return beginConn ( )
101127 } )
102128
103129 _synReply ( {
@@ -162,6 +188,7 @@ function doHttpUp(cfg) {
162188 uid,
163189 } ,
164190 body : buf ,
191+ agent : defaultAgent
165192 } )
166193 return sendReq
167194}
0 commit comments