Skip to content

Commit 31d5773

Browse files
kumarakBethGriggs
authored andcommitted
http2: add tests for cancel event while client is paused reading
PR-URL: #39622 Refs: #39423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Beth Griggs <[email protected]>
1 parent a3c33d4 commit 31d5773

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
const common = require('../common');
3+
const fixtures = require('../common/fixtures');
4+
if (!common.hasCrypto) {
5+
common.skip('missing crypto');
6+
}
7+
8+
const http2 = require('http2');
9+
const key = fixtures.readKey('agent1-key.pem', 'binary');
10+
const cert = fixtures.readKey('agent1-cert.pem', 'binary');
11+
12+
const server = http2.createSecureServer({ key, cert });
13+
14+
let client_stream;
15+
16+
server.on('stream', common.mustCall(function(stream) {
17+
stream.resume();
18+
stream.on('data', function(chunk) {
19+
stream.write(chunk);
20+
client_stream.pause();
21+
client_stream.close(http2.constants.NGHTTP2_CANCEL);
22+
});
23+
}));
24+
25+
server.listen(0, function() {
26+
const client = http2.connect(`https://localhost:${server.address().port}`,
27+
{ rejectUnauthorized: false }
28+
);
29+
client_stream = client.request({ ':method': 'POST' });
30+
client_stream.on('close', common.mustCall(() => {
31+
client.close();
32+
server.close();
33+
}));
34+
client_stream.resume();
35+
client_stream.write(Buffer.alloc(1024 * 1024));
36+
});

0 commit comments

Comments
 (0)