http2: fix condition where data is lost · nodejs/node@ef8f90f · GitHub
Skip to content

Commit ef8f90f

Browse files
mcollinaaddaleax
authored andcommitted
http2: fix condition where data is lost
PR-URL: #18895 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent e74e422 commit ef8f90f

3 files changed

Lines changed: 146 additions & 14 deletions

File tree

lib/internal/http2/core.js

Lines changed: 41 additions & 14 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const assert = require('assert');
7+
const http2 = require('http2');
8+
const { Readable } = require('stream');
9+
10+
const server = http2.createServer(common.mustCall((req, res) => {
11+
res.setHeader('content-type', 'text/html');
12+
const input = new Readable({
13+
read() {
14+
this.push('test');
15+
this.push(null);
16+
}
17+
});
18+
input.pipe(res);
19+
}));
20+
21+
server.listen(0, common.mustCall(() => {
22+
const port = server.address().port;
23+
const client = http2.connect(`http://localhost:${port}`);
24+
25+
const req = client.request();
26+
27+
req.on('response', common.mustCall((headers) => {
28+
assert.strictEqual(headers[':status'], 200);
29+
assert.strictEqual(headers['content-type'], 'text/html');
30+
}));
31+
32+
let data = '';
33+
34+
const notCallClose = common.mustNotCall();
35+
36+
setTimeout(() => {
37+
req.setEncoding('utf8');
38+
req.removeListener('close', notCallClose);
39+
req.on('close', common.mustCall(() => {
40+
server.close();
41+
client.close();
42+
}));
43+
req.on('data', common.mustCallAtLeast((d) => data += d));
44+
req.on('end', common.mustCall(() => {
45+
assert.strictEqual(data, 'test');
46+
}));
47+
}, common.platformTimeout(100));
48+
49+
req.on('close', notCallClose);
50+
}));
Lines changed: 55 additions & 0 deletions

0 commit comments

Comments
 (0)