mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 19:38:23 +00:00

This update does several significant things: 1. It eliminates the base Nghttp2* classes and folds those in to node::http2::Http2Session and node::http2::Http2Stream 2. It makes node::http2::Http2Stream a StreamBase instance and sends that out to JS-land to act as the [kHandle] for the JavaScript Http2Stream class. 3. It shifts some of the callbacks from C++ off of the JavaScript Http2Session class to the Http2Stream class. 4. It refactors the data provider structure for FD and Stream based sending to help encapsulate those functions easier 5. It streamlines some of the functions at the C++ layer to eliminate now unnecessary redirections 6. It cleans up node_http2.cc for better readability and maintainability 7. It refactors some of the debug output 8. Because Http2Stream instances are now StreamBases, they are now also trackable using async-hooks 9. The Stream::OnRead algorithm has been simplified with a couple bugs fixed. 10. I've eliminated node_http2_core.h and node_http2_core-inl.h 11. Detect invalid handshake a report protocol error to session 12. Refactor out of memory error, improve other errors 13. Add Http2Session.prototype.ping PR-URL: https://github.com/nodejs/node/pull/17105 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sebastiaan Deckers <sebdeckers83@gmail.com>
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const h2 = require('http2');
|
|
|
|
const server = h2.createServer();
|
|
|
|
server.on(
|
|
'stream',
|
|
common.mustCall((stream) => {
|
|
stream.session.destroy();
|
|
|
|
// Test that stream.state getter returns an empty object
|
|
// when the stream session has been destroyed
|
|
assert.deepStrictEqual({}, stream.state);
|
|
|
|
// Test that ERR_HTTP2_INVALID_STREAM is thrown while calling
|
|
// stream operations after the stream session has been destroyed
|
|
const invalidStreamError = {
|
|
type: Error,
|
|
code: 'ERR_HTTP2_INVALID_STREAM',
|
|
message: 'The stream has been destroyed'
|
|
};
|
|
common.expectsError(() => stream.additionalHeaders(), invalidStreamError);
|
|
common.expectsError(() => stream.priority(), invalidStreamError);
|
|
common.expectsError(
|
|
() => stream.pushStream({}, common.mustNotCall()),
|
|
invalidStreamError
|
|
);
|
|
common.expectsError(() => stream.respond(), invalidStreamError);
|
|
common.expectsError(() => stream.write('data'), invalidStreamError);
|
|
|
|
// Test that ERR_HTTP2_INVALID_SESSION is thrown while calling
|
|
// session operations after the stream session has been destroyed
|
|
const invalidSessionError = {
|
|
type: Error,
|
|
code: 'ERR_HTTP2_INVALID_SESSION',
|
|
message: 'The session has been destroyed'
|
|
};
|
|
common.expectsError(() => stream.session.settings(), invalidSessionError);
|
|
common.expectsError(() => stream.session.shutdown(), invalidSessionError);
|
|
|
|
// Wait for setImmediate call from destroy() to complete
|
|
// so that state.destroyed is set to true
|
|
setImmediate((session) => {
|
|
common.expectsError(() => session.settings(), invalidSessionError);
|
|
common.expectsError(() => session.shutdown(), invalidSessionError);
|
|
}, stream.session);
|
|
})
|
|
);
|
|
|
|
server.listen(
|
|
0,
|
|
common.mustCall(() => {
|
|
const client = h2.connect(`http://localhost:${server.address().port}`);
|
|
const req = client.request();
|
|
req.resume();
|
|
req.on('end', common.mustCall(() => server.close()));
|
|
})
|
|
);
|