mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
508890d795
PR-URL: https://github.com/nodejs/node/pull/39928 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
const server = http2.createServer();
|
|
const errRegEx = /Session closed with error code 7/;
|
|
const destroyCode = http2.constants.NGHTTP2_REFUSED_STREAM;
|
|
|
|
server.on('error', common.mustNotCall());
|
|
|
|
server.on('session', (session) => {
|
|
session.on('close', common.mustCall());
|
|
session.on('error', common.mustCall((err) => {
|
|
assert.match(err.message, errRegEx);
|
|
assert.strictEqual(session.closed, false);
|
|
assert.strictEqual(session.destroyed, true);
|
|
}));
|
|
|
|
session.on('stream', common.mustCall((stream) => {
|
|
stream.on('error', common.mustCall((err) => {
|
|
assert.match(err.message, errRegEx);
|
|
assert.strictEqual(session.closed, false);
|
|
assert.strictEqual(session.destroyed, true);
|
|
assert.strictEqual(stream.rstCode, destroyCode);
|
|
}));
|
|
|
|
session.destroy(destroyCode);
|
|
}));
|
|
});
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const session = http2.connect(`http://localhost:${server.address().port}`);
|
|
|
|
session.on('error', common.mustCall((err) => {
|
|
assert.match(err.message, errRegEx);
|
|
assert.strictEqual(session.closed, false);
|
|
assert.strictEqual(session.destroyed, true);
|
|
}));
|
|
|
|
const stream = session.request({ [http2.constants.HTTP2_HEADER_PATH]: '/' });
|
|
|
|
stream.on('error', common.mustCall((err) => {
|
|
assert.match(err.message, errRegEx);
|
|
assert.strictEqual(stream.rstCode, destroyCode);
|
|
}));
|
|
|
|
stream.on('close', common.mustCall(() => {
|
|
server.close();
|
|
}));
|
|
}));
|