http2: skip writeHead if stream is closed
Fixes: https://github.com/nodejs/node/issues/57416 PR-URL: https://github.com/nodejs/node/pull/57686 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
This commit is contained in:
parent
d582954434
commit
cdf3fa241c
@ -706,7 +706,7 @@ class Http2ServerResponse extends Stream {
|
|||||||
writeHead(statusCode, statusMessage, headers) {
|
writeHead(statusCode, statusMessage, headers) {
|
||||||
const state = this[kState];
|
const state = this[kState];
|
||||||
|
|
||||||
if (state.closed || this.stream.destroyed)
|
if (state.closed || this.stream.destroyed || this.stream.closed)
|
||||||
return this;
|
return this;
|
||||||
if (this[kStream].headersSent)
|
if (this[kStream].headersSent)
|
||||||
throw new ERR_HTTP2_HEADERS_SENT();
|
throw new ERR_HTTP2_HEADERS_SENT();
|
||||||
|
23
test/parallel/test-http2-compat-write-head-after-close.js
Normal file
23
test/parallel/test-http2-compat-write-head-after-close.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
if (!common.hasCrypto) { common.skip('missing crypto'); }
|
||||||
|
const h2 = require('http2');
|
||||||
|
|
||||||
|
const server = h2.createServer((req, res) => {
|
||||||
|
const stream = req.stream;
|
||||||
|
stream.close();
|
||||||
|
res.writeHead(200, { 'content-type': 'text/plain' });
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(0, common.mustCall(() => {
|
||||||
|
const port = server.address().port;
|
||||||
|
const client = h2.connect(`http://localhost:${port}`);
|
||||||
|
const req = client.request({ ':path': '/' });
|
||||||
|
req.on('response', common.mustNotCall('head after close should not be sent'));
|
||||||
|
req.on('end', common.mustCall(() => {
|
||||||
|
client.close();
|
||||||
|
server.close();
|
||||||
|
}));
|
||||||
|
req.end();
|
||||||
|
}));
|
Loading…
x
Reference in New Issue
Block a user