Skip to content

Commit 11e7f62

Browse files
committed
http2: Http2ServerResponse.end() should always return self
1 parent b2e4cb7 commit 11e7f62

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/internal/http2/compat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ class Http2ServerResponse extends Stream {
616616

617617
if ((state.closed || state.ending) &&
618618
state.headRequest === stream.headRequest) {
619-
return false;
619+
return this;
620620
}
621621

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

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

Lines changed: 28 additions & 0 deletions
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)