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: do no throw in writeHead if state.closed #27682

Closed
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
7 changes: 2 additions & 5 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,11 @@ class Http2ServerResponse extends Stream {
writeHead(statusCode, statusMessage, headers) {
const state = this[kState];

if (state.closed)
throw new ERR_HTTP2_INVALID_STREAM();
if (state.closed || this.stream.destroyed)
return this;
if (this[kStream].headersSent)
throw new ERR_HTTP2_HEADERS_SENT();

if (this.stream.destroyed)
return this;

if (typeof statusMessage === 'string')
statusMessageWarn();

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http2-compat-serverresponse-writehead.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ server.listen(0, common.mustCall(function() {
response.on('finish', common.mustCall(function() {
server.close();
process.nextTick(common.mustCall(() => {
common.expectsError(() => { response.writeHead(300); }, {
code: 'ERR_HTTP2_INVALID_STREAM'
});
// The stream is invalid at this point,
// and this line verifies this does not throw.
response.writeHead(300);
}));
}));
response.end();
Expand Down