http2: do no throw in writeHead if state.closed

The http1 implementation does not throw if the connection is down.
The http2 compat implementation should do the same.

See: https://github.com/fastify/fastify-http-proxy/issues/51.
See: https://github.com/fastify/fastify/issues/1494.

PR-URL: https://github.com/nodejs/node/pull/27682
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
pull/25518/head
Matteo Collina 2019-05-13 19:41:48 +02:00
parent 030fa2ea44
commit a49ab0f89e
2 changed files with 5 additions and 8 deletions

View File

@ -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();

View File

@ -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();