mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00

This one was a bit of a rabbit hole... but, with this set of changes, `QuicStream` should now work with autoDestroy, supports a promisified `close()`, and fixes a number of other internal bugs that were spotted trying to get it to work. PR-URL: https://github.com/nodejs/node/pull/34351 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
// Flags: --no-warnings
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasQuic)
|
|
common.skip('missing quic');
|
|
|
|
const { key, cert, ca } = require('../common/quic');
|
|
|
|
const { createWriteStream } = require('fs');
|
|
const { createQuicSocket } = require('net');
|
|
const { strictEqual } = require('assert');
|
|
|
|
const qlog = process.env.NODE_QLOG === '1';
|
|
|
|
const options = { key, cert, ca, alpn: 'zzz', qlog };
|
|
|
|
const client = createQuicSocket({ qlog, client: options });
|
|
const server = createQuicSocket({ qlog, server: options });
|
|
|
|
server.on('close', common.mustCall());
|
|
client.on('close', common.mustCall());
|
|
|
|
(async function() {
|
|
server.on('session', common.mustCall(async (session) => {
|
|
if (qlog) session.qlog.pipe(createWriteStream('server.qlog'));
|
|
const stream = await session.openStream({ halfOpen: true });
|
|
stream.write('from the ');
|
|
setTimeout(() => stream.end('server'), common.platformTimeout(10));
|
|
stream.on('close', common.mustCall());
|
|
session.on('close', common.mustCall(() => {
|
|
server.close();
|
|
}));
|
|
}));
|
|
|
|
await server.listen();
|
|
|
|
const req = await client.connect({
|
|
address: 'localhost',
|
|
port: server.endpoints[0].address.port
|
|
});
|
|
if (qlog) req.qlog.pipe(createWriteStream('client.qlog'));
|
|
|
|
req.on('close', common.mustCall());
|
|
|
|
req.on('stream', common.mustCall(async (stream) => {
|
|
let data = '';
|
|
stream.setEncoding('utf8');
|
|
stream.on('close', common.mustCall());
|
|
|
|
for await (const chunk of stream)
|
|
data += chunk;
|
|
|
|
strictEqual(data, 'from the server');
|
|
|
|
await req.close();
|
|
|
|
client.close();
|
|
}));
|
|
})().then(common.mustCall());
|