Skip to content

Commit 0712530

Browse files
enable keepAlive
1 parent ca76f18 commit 0712530

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/proxy.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Proxy.prototype.listen = function(options, callback) {
4848
this.silent = !!options.silent;
4949
this.httpPort = options.port || 8080;
5050
this.timeout = options.timeout || 0;
51-
this.httpAgent = options.httpAgent || new http.Agent();
52-
this.httpsAgent = options.httpsAgent || new https.Agent();
51+
this.httpAgent = options.httpAgent || new http.Agent({ keepAlive: true });
52+
this.httpsAgent = options.httpsAgent || new https.Agent({ keepAlive: true });
5353
this.forceSNI = !!options.forceSNI;
5454
if (this.forceSNI && !this.silent) {
5555
console.log('SNI enabled. Clients not supporting SNI may fail');
@@ -703,7 +703,10 @@ Proxy.prototype._onHttpServerRequest = function(isSSL, clientToProxyRequest, pro
703703
}
704704
ctx.serverToProxyResponse.headers['transfer-encoding'] = 'chunked';
705705
delete ctx.serverToProxyResponse.headers['content-length'];
706-
ctx.serverToProxyResponse.headers['connection'] = 'close';
706+
if (!ctx.serverToProxyResponse.headers['connection']) {
707+
var keepAlive = ctx.clientToProxyRequest.headers && ctx.clientToProxyRequest.headers['connection'] && ctx.clientToProxyRequest.headers['connection'].trim().toLowerCase() === 'keep-alive';
708+
ctx.serverToProxyResponse.headers['connection'] = keepAlive ? 'keep-alive' : 'close';
709+
}
707710
return self._onResponseHeaders(ctx, function (err) {
708711
if (err) {
709712
return self._onError('ON_RESPONSEHEADERS_ERROR', ctx, err);

0 commit comments

Comments
 (0)