Skip to content

Commit cdf3fa2

Browse files
islandryumarco-ippolito
authored andcommitted
http2: skip writeHead if stream is closed
Fixes: #57416 PR-URL: #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>
1 parent d582954 commit cdf3fa2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/internal/http2/compat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ class Http2ServerResponse extends Stream {
706706
writeHead(statusCode, statusMessage, headers) {
707707
const state = this[kState];
708708

709-
if (state.closed || this.stream.destroyed)
709+
if (state.closed || this.stream.destroyed || this.stream.closed)
710710
return this;
711711
if (this[kStream].headersSent)
712712
throw new ERR_HTTP2_HEADERS_SENT();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto) { common.skip('missing crypto'); }
5+
const h2 = require('http2');
6+
7+
const server = h2.createServer((req, res) => {
8+
const stream = req.stream;
9+
stream.close();
10+
res.writeHead(200, { 'content-type': 'text/plain' });
11+
});
12+
13+
server.listen(0, common.mustCall(() => {
14+
const port = server.address().port;
15+
const client = h2.connect(`http://localhost:${port}`);
16+
const req = client.request({ ':path': '/' });
17+
req.on('response', common.mustNotCall('head after close should not be sent'));
18+
req.on('end', common.mustCall(() => {
19+
client.close();
20+
server.close();
21+
}));
22+
req.end();
23+
}));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy