From ecb5738711b5edf4955d4dd56b11cedfcdc1e9d8 Mon Sep 17 00:00:00 2001 From: xiamengyu Date: Fri, 23 Jun 2017 17:24:52 +0800 Subject: [PATCH 1/3] support tcp NO_DELAY option --- lib/node/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/node/index.js b/lib/node/index.js index 6dce9153c..8b00409f2 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -550,6 +550,17 @@ Request.prototype.cert = function(cert){ return this; }; +/** + * Set tcp no delay option + * + * @param noDelay + * @returns {*} + */ +Request.prototype.setNoDelay = function(noDelay){ + this._noDelay = noDelay === true; + return this; +}; + /** * Return an http[s] request. * @@ -609,6 +620,12 @@ Request.prototype.request = function(){ // request var req = this.req = mod.request(options); + + // set tcp no delay + if (true === this._noDelay) { + req.setNoDelay(true); + } + if ('HEAD' != options.method) { req.setHeader('Accept-Encoding', 'gzip, deflate'); } From ec7900e3518ab997e9027267feb1365fffa43f02 Mon Sep 17 00:00:00 2001 From: xiamengyu Date: Fri, 23 Jun 2017 19:09:40 +0800 Subject: [PATCH 2/3] fix setNoDelay in IE 10 --- lib/node/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node/index.js b/lib/node/index.js index 8b00409f2..dd936cd91 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -622,9 +622,8 @@ Request.prototype.request = function(){ var req = this.req = mod.request(options); // set tcp no delay - if (true === this._noDelay) { - req.setNoDelay(true); - } + req.setNoDelay && req.setNoDelay(!!this._noDelay); + if ('HEAD' != options.method) { req.setHeader('Accept-Encoding', 'gzip, deflate'); From 1c4e7995df2cc4657da0ca22431e083fae3ffba8 Mon Sep 17 00:00:00 2001 From: xiamengyu Date: Sun, 25 Jun 2017 09:40:57 +0800 Subject: [PATCH 3/3] keep node default behaviour for TCP NO_DELAY option --- lib/node/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/node/index.js b/lib/node/index.js index dd936cd91..0cf7dc3c8 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -622,8 +622,9 @@ Request.prototype.request = function(){ var req = this.req = mod.request(options); // set tcp no delay - req.setNoDelay && req.setNoDelay(!!this._noDelay); - + if (this._noDelay === true && req.setNoDelay) { + req.setNoDelay(true); + } if ('HEAD' != options.method) { req.setHeader('Accept-Encoding', 'gzip, deflate');