Skip to content

Commit

Permalink
http2: Http2ServerResponse.end() should always return self
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ronag authored and BethGriggs committed Apr 16, 2019
1 parent 6bc7fd9 commit 59b348e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-http2-compat-serverresponse-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 59b348e

Please sign in to comment.