File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,6 @@ class ConfigurableProxy extends EventEmitter {
173
173
} ) ;
174
174
}
175
175
options . ws = true ;
176
- this . agent = options . agent = new http . Agent ( { keepAlive : true } ) ;
177
176
var proxy = ( this . proxy = httpProxy . createProxyServer ( options ) ) ;
178
177
179
178
// tornado-style regex routing,
@@ -220,9 +219,14 @@ class ConfigurableProxy extends EventEmitter {
220
219
this . metricsServer = http . createServer ( metricsCallback ) ;
221
220
}
222
221
222
+ // need separate agents for http and https requests
223
+ // these agents allow our _upstream_ sockets to be kept alive
224
+ this . httpAgent = http . globalAgent = new http . Agent ( { keepAlive : true } ) ;
225
+ this . httpsAgent = https . globalAgent = new https . Agent ( { keepAlive : true } ) ;
226
+
227
+ // these settings configure requests to the proxy itself to accept keep-alive
223
228
var httpOptions = {
224
229
keepAlive : true ,
225
- agent : this . agent ,
226
230
keepAliveTimeout : this . options . keepAliveTimeout || 5000 ,
227
231
} ;
228
232
@@ -560,7 +564,13 @@ class ConfigurableProxy extends EventEmitter {
560
564
}
561
565
562
566
// add config argument
563
- args . push ( { target : target } ) ;
567
+ var proxyOptions = { target : target } ;
568
+ if ( target . protocol . slice ( - 2 ) === "s:" ) {
569
+ proxyOptions . agent = that . httpsAgent ;
570
+ } else {
571
+ proxyOptions . agent = that . httpAgent ;
572
+ }
573
+ args . push ( proxyOptions ) ;
564
574
565
575
// add error handling
566
576
args . push ( function ( e ) {
You can’t perform that action at this time.
0 commit comments