node/test/parallel/test-http2-client-settings-before-connect.js
James M Snell 0babd181a0 http2: cleanup Http2Stream/Http2Session destroy
PR-URL: https://github.com/nodejs/node/pull/17406
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

This is a significant cleanup and refactoring of the
cleanup/close/destroy logic for Http2Stream and Http2Session.
There are significant changes here in the timing and ordering
of cleanup logic, JS apis. and various related necessary edits.
2017-12-18 10:19:21 -08:00

56 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const h2 = require('http2');
const server = h2.createServer();
// we use the lower-level API here
server.on('stream', common.mustCall((stream, headers, flags) => {
stream.respond();
stream.end('ok');
}));
server.on('session', common.mustCall((session) => {
session.on('remoteSettings', common.mustCall(2));
}));
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
[
['headerTableSize', -1, RangeError],
['headerTableSize', 2 ** 32, RangeError],
['initialWindowSize', -1, RangeError],
['initialWindowSize', 2 ** 32, RangeError],
['maxFrameSize', 1, RangeError],
['maxFrameSize', 2 ** 24, RangeError],
['maxConcurrentStreams', -1, RangeError],
['maxConcurrentStreams', 2 ** 31, RangeError],
['maxHeaderListSize', -1, RangeError],
['maxHeaderListSize', 2 ** 32, RangeError],
['enablePush', 'a', TypeError],
['enablePush', 1, TypeError],
['enablePush', 0, TypeError],
['enablePush', null, TypeError],
['enablePush', {}, TypeError]
].forEach((i) => {
common.expectsError(
() => client.settings({ [i[0]]: i[1] }),
{
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: i[2] });
});
client.settings({ maxFrameSize: 1234567 });
const req = client.request();
req.on('response', common.mustCall());
req.resume();
req.on('close', common.mustCall(() => {
server.close();
client.close();
}));
}));