Skip to content

Commit 59b348e

Browse files
ronagBethGriggs
authored andcommitted
http2: Http2ServerResponse.end() should always return self
PR-URL: #24346 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 6bc7fd9 commit 59b348e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/internal/http2/compat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ class Http2ServerResponse extends Stream {
650650

651651
if ((state.closed || state.ending) &&
652652
state.headRequest === stream.headRequest) {
653-
return false;
653+
return this;
654654
}
655655

656656
if (typeof chunk === 'function') {

test/parallel/test-http2-compat-serverresponse-end.js

+28
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@ const {
6060
}));
6161
}
6262

63+
{
64+
// Http2ServerResponse.end should return self after end
65+
const server = createServer(mustCall((request, response) => {
66+
strictEqual(response, response.end());
67+
strictEqual(response, response.end());
68+
server.close();
69+
}));
70+
server.listen(0, mustCall(() => {
71+
const { port } = server.address();
72+
const url = `http://localhost:${port}`;
73+
const client = connect(url, mustCall(() => {
74+
const headers = {
75+
':path': '/',
76+
':method': 'GET',
77+
':scheme': 'http',
78+
':authority': `localhost:${port}`
79+
};
80+
const request = client.request(headers);
81+
request.setEncoding('utf8');
82+
request.on('end', mustCall(() => {
83+
client.close();
84+
}));
85+
request.end();
86+
request.resume();
87+
}));
88+
}));
89+
}
90+
6391
{
6492
// Http2ServerResponse.end can omit encoding arg, sets it to utf-8
6593
const server = createServer(mustCall((request, response) => {

0 commit comments

Comments
 (0)