From 28dcfd17d8387c2c4283d4873c53b3e02d6ea5a7 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sat, 11 Apr 2020 16:06:43 -0400 Subject: [PATCH] http: return this from IncomingMessage#destroy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates IncomingMessage#destroy() to return `this` for consistency with other readable streams. PR-URL: https://github.com/nodejs/node/pull/32789 Fixes: https://github.com/nodejs/node/issues/32772 Reviewed-By: Robert Nagy Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso Reviewed-By: Ruben Bridgewater --- doc/api/http.md | 6 ++++++ lib/_http_incoming.js | 1 + test/parallel/test-http-incoming-message-destroy.js | 10 ++++++++++ 3 files changed, 17 insertions(+) create mode 100644 test/parallel/test-http-incoming-message-destroy.js diff --git a/doc/api/http.md b/doc/api/http.md index 97bfc36233b0bc..75c5292ab9127a 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1875,9 +1875,15 @@ const req = http.request({ ### `message.destroy([error])` * `error` {Error} +* Returns: {this} Calls `destroy()` on the socket that received the `IncomingMessage`. If `error` is provided, an `'error'` event is emitted on the socket and `error` is passed diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 02b88dfe87ca85..59136833c6b340 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -123,6 +123,7 @@ IncomingMessage.prototype.destroy = function destroy(error) { this.destroyed = true; if (this.socket) this.socket.destroy(error); + return this; }; diff --git a/test/parallel/test-http-incoming-message-destroy.js b/test/parallel/test-http-incoming-message-destroy.js new file mode 100644 index 00000000000000..4241ec8e7d85ef --- /dev/null +++ b/test/parallel/test-http-incoming-message-destroy.js @@ -0,0 +1,10 @@ +'use strict'; + +// Test that http.IncomingMessage,prototype.destroy() returns `this`. +require('../common'); + +const assert = require('assert'); +const http = require('http'); +const incomingMessage = new http.IncomingMessage(); + +assert.strictEqual(incomingMessage.destroy(), incomingMessage);