mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 23:52:40 +00:00

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.
33 lines
865 B
JavaScript
33 lines
865 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const h2 = require('http2');
|
|
|
|
// Server request and response should receive close event
|
|
// if the connection was terminated before response.end
|
|
// could be called or flushed
|
|
|
|
const server = h2.createServer(common.mustCall((req, res) => {
|
|
res.writeHead(200);
|
|
res.write('a');
|
|
|
|
req.on('close', common.mustCall());
|
|
res.on('close', common.mustCall());
|
|
req.on('error', common.mustNotCall());
|
|
}));
|
|
server.listen(0);
|
|
|
|
server.on('listening', () => {
|
|
const url = `http://localhost:${server.address().port}`;
|
|
const client = h2.connect(url, common.mustCall(() => {
|
|
const request = client.request();
|
|
request.on('data', common.mustCall(function(chunk) {
|
|
client.destroy();
|
|
server.close();
|
|
}));
|
|
}));
|
|
});
|