-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-http2-client-cancel-stream-after-end.js
More file actions
43 lines (33 loc) · 1.22 KB
/
test-http2-client-cancel-stream-after-end.js
File metadata and controls
43 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const h2 = require('http2');
// Regression test for https://github.com/nodejs/node/issues/56627
// When a client stream's writable side is already ended (e.g. GET request)
// and the server destroys the session, the client stream should emit an
// error event with RST code NGHTTP2_CANCEL, since the 'aborted' event
// cannot be emitted when the writable side is already ended.
{
const server = h2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.session.destroy();
}));
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
client.on('close', common.mustCall(() => {
server.close();
}));
const req = client.request();
req.on('error', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR');
assert.match(err.message, /NGHTTP2_CANCEL/);
}));
req.on('aborted', common.mustNotCall());
req.on('close', common.mustCall(() => {
assert.strictEqual(req.rstCode, h2.constants.NGHTTP2_CANCEL);
}));
req.resume();
}));
}