From 59b348e0e42cdb3cb00c1f3bc9817349fbf182b2 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 13 Nov 2018 23:33:14 +0100 Subject: [PATCH] http2: `Http2ServerResponse.end()` should always return self PR-URL: https://github.com/nodejs/node/pull/24346 Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig --- lib/internal/http2/compat.js | 2 +- .../test-http2-compat-serverresponse-end.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 9bf180e4636de4..3e18ca36544026 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -650,7 +650,7 @@ class Http2ServerResponse extends Stream { if ((state.closed || state.ending) && state.headRequest === stream.headRequest) { - return false; + return this; } if (typeof chunk === 'function') { diff --git a/test/parallel/test-http2-compat-serverresponse-end.js b/test/parallel/test-http2-compat-serverresponse-end.js index 0e846a5948e3cc..b999dadabcedd4 100644 --- a/test/parallel/test-http2-compat-serverresponse-end.js +++ b/test/parallel/test-http2-compat-serverresponse-end.js @@ -60,6 +60,34 @@ const { })); } +{ + // Http2ServerResponse.end should return self after end + const server = createServer(mustCall((request, response) => { + strictEqual(response, response.end()); + strictEqual(response, response.end()); + server.close(); + })); + server.listen(0, mustCall(() => { + const { port } = server.address(); + const url = `http://localhost:${port}`; + const client = connect(url, mustCall(() => { + const headers = { + ':path': '/', + ':method': 'GET', + ':scheme': 'http', + ':authority': `localhost:${port}` + }; + const request = client.request(headers); + request.setEncoding('utf8'); + request.on('end', mustCall(() => { + client.close(); + })); + request.end(); + request.resume(); + })); + })); +} + { // Http2ServerResponse.end can omit encoding arg, sets it to utf-8 const server = createServer(mustCall((request, response) => {