diff options
author | Matteo Collina <hello@matteocollina.com> | 2018-02-14 12:32:01 +0000 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2018-02-19 08:59:32 +0100 |
commit | 8118da7430c33fc80a2f60c4a8cb3f568edbb29b (patch) | |
tree | 2586e96efc2f5cfe969623e3670e02566786689d | |
parent | f6721c20df67c0f5bbd1ea58d304159160be03f1 (diff) | |
download | android-node-v8-8118da7430c33fc80a2f60c4a8cb3f568edbb29b.tar.gz android-node-v8-8118da7430c33fc80a2f60c4a8cb3f568edbb29b.tar.bz2 android-node-v8-8118da7430c33fc80a2f60c4a8cb3f568edbb29b.zip |
http: OutgoingMessage.end() should return this
PR-URL: https://github.com/nodejs/node/pull/18780
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
-rw-r--r-- | doc/api/http.md | 10 | ||||
-rw-r--r-- | lib/_http_outgoing.js | 9 | ||||
-rw-r--r-- | test/parallel/test-http-request-end-twice.js | 2 | ||||
-rw-r--r-- | test/parallel/test-http-request-end.js | 8 |
4 files changed, 21 insertions, 8 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index 74ba9e8792..daa058a8b0 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -544,11 +544,16 @@ See [`request.socket`][] ### request.end([data[, encoding]][, callback]) <!-- YAML added: v0.1.90 +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/18780 + description: This method now returns a reference to `ClientRequest`. --> * `data` {string|Buffer} * `encoding` {string} * `callback` {Function} +* Returns: {this} Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream. If the request is @@ -1041,11 +1046,16 @@ See [`response.socket`][]. ### response.end([data][, encoding][, callback]) <!-- YAML added: v0.1.90 +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/18780 + description: This method now returns a reference to `ServerResponse`. --> * `data` {string|Buffer} * `encoding` {string} * `callback` {Function} +* Returns: {this} This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index f513315b7c..985b74679c 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -736,7 +736,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { } if (this.finished) { - return false; + return this; } var uncork; @@ -766,12 +766,11 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { var finish = onFinish.bind(undefined, this); - var ret; if (this._hasBody && this.chunkedEncoding) { - ret = this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish); + this._send('0\r\n' + this._trailer + '\r\n', 'latin1', finish); } else { // Force a flush, HACK. - ret = this._send('', 'latin1', finish); + this._send('', 'latin1', finish); } if (uncork) @@ -788,7 +787,7 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { this._finish(); } - return ret; + return this; }; diff --git a/test/parallel/test-http-request-end-twice.js b/test/parallel/test-http-request-end-twice.js index 525377d2e1..47f08fd6e4 100644 --- a/test/parallel/test-http-request-end-twice.js +++ b/test/parallel/test-http-request-end-twice.js @@ -31,7 +31,7 @@ const server = http.Server(function(req, res) { server.listen(0, function() { const req = http.get({ port: this.address().port }, function(res) { res.on('end', function() { - assert.ok(!req.end()); + assert.strictEqual(req.end(), req); server.close(); }); res.resume(); diff --git a/test/parallel/test-http-request-end.js b/test/parallel/test-http-request-end.js index 6dd5fa4e91..a0cdcf27dd 100644 --- a/test/parallel/test-http-request-end.js +++ b/test/parallel/test-http-request-end.js @@ -44,7 +44,7 @@ const server = http.Server(function(req, res) { }); server.listen(0, function() { - http.request({ + const req = http.request({ port: this.address().port, path: '/', method: 'POST' @@ -54,5 +54,9 @@ server.listen(0, function() { }).on('error', function(e) { console.log(e.message); process.exit(1); - }).end(expected); + }); + + const result = req.end(expected); + + assert.strictEqual(req, result); }); |