Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: always call callback on Http2ServerResponse#end #33911

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,6 @@ class Http2ServerResponse extends Stream {
const stream = this[kStream];
const state = this[kState];

if ((state.closed || state.ending) &&
state.headRequest === stream.headRequest) {
return this;
}

if (typeof chunk === 'function') {
cb = chunk;
chunk = null;
Expand All @@ -722,6 +717,14 @@ class Http2ServerResponse extends Stream {
encoding = 'utf8';
}

if ((state.closed || state.ending) &&
state.headRequest === stream.headRequest) {
if (typeof cb === 'function') {
process.nextTick(cb);
}
return this;
}

if (chunk !== null && chunk !== undefined)
this.write(chunk, encoding);

Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-http2-compat-serverresponse-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ const {
// but callback will only be called once
const server = createServer(mustCall((request, response) => {
response.end('end', 'utf8', mustCall(() => {
response.end(mustNotCall());
response.end(mustCall());
process.nextTick(() => {
response.end(mustNotCall());
response.end(mustCall());
server.close();
});
}));
response.on('finish', mustCall(() => {
response.end(mustNotCall());
response.end(mustCall());
}));
response.end(mustNotCall());
response.end(mustCall());
}));
server.listen(0, mustCall(() => {
let data = '';
Expand Down Expand Up @@ -294,7 +294,7 @@ const {
}));
response.end('data', mustCall(() => {
strictEqual(finished, false);
response.end('data', mustNotCall());
response.end('data', mustCall());
}));
}));
server.listen(0, mustCall(() => {
Expand Down Expand Up @@ -328,7 +328,7 @@ const {
// Should be able to respond to HEAD with just .end
const server = createServer(mustCall((request, response) => {
response.end('data', mustCall());
response.end(mustNotCall());
response.end(mustCall());
}));
server.listen(0, mustCall(() => {
const { port } = server.address();
Expand Down