From 2ddbbfd164e612eb75b18846ae650d4ffbb2164a Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sun, 4 Oct 2015 00:01:06 -0400 Subject: [PATCH] http: cork/uncork before flushing pipelined res Make sure that the pipelined response data will be written as less TCP packets as possible. PR-URL: https://github.com/nodejs/node/pull/3172 Reviewed-By: Brian White Reviewed-By: Trevor Norris --- lib/_http_outgoing.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 7bf8d563e55455..dd78ddf645f1e5 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -157,10 +157,12 @@ OutgoingMessage.prototype._writeRaw = function(data, encoding, callback) { var output = this.output; var outputEncodings = this.outputEncodings; var outputCallbacks = this.outputCallbacks; + connection.cork(); for (var i = 0; i < outputLength; i++) { connection.write(output[i], outputEncodings[i], outputCallbacks[i]); } + connection.uncork(); this.output = []; this.outputEncodings = []; @@ -637,10 +639,12 @@ OutgoingMessage.prototype._flush = function() { var output = this.output; var outputEncodings = this.outputEncodings; var outputCallbacks = this.outputCallbacks; + socket.cork(); for (var i = 0; i < outputLength; i++) { ret = socket.write(output[i], outputEncodings[i], outputCallbacks[i]); } + socket.uncork(); this.output = []; this.outputEncodings = [];