From 3d93f39190ec24284aee6acd0e0214862e651567 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 14 Feb 2018 13:39:05 +0000 Subject: [PATCH] http2: make response.end() return this PR-URL: https://github.com/nodejs/node/pull/18780 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Benjamin Gruenbaum Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca --- doc/api/http2.md | 5 +++++ lib/internal/http2/compat.js | 2 ++ test/parallel/test-http2-compat-serverrequest-end.js | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/http2.md b/doc/api/http2.md index 66cf7aafa0ff48..c73ed3b0bd2fb1 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -2624,11 +2624,16 @@ See [`response.socket`][]. #### response.end([data][, encoding][, callback]) * `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/internal/http2/compat.js b/lib/internal/http2/compat.js index 5e6c51377e94ba..9670843176b77e 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -596,6 +596,8 @@ class Http2ServerResponse extends Stream { this[kFinish](); else stream.end(); + + return this; } destroy(err) { diff --git a/test/parallel/test-http2-compat-serverrequest-end.js b/test/parallel/test-http2-compat-serverrequest-end.js index d34372118582db..45a678d1a950d1 100644 --- a/test/parallel/test-http2-compat-serverrequest-end.js +++ b/test/parallel/test-http2-compat-serverrequest-end.js @@ -26,7 +26,7 @@ server.listen(0, common.mustCall(function() { server.close(); })); - response.end(); + assert.strictEqual(response.end(), response); })); }));