0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-http2-allow-http1.js
xsbchen d1114c485d
http2: close idle connections when allowHTTP1 is true
Fixes: https://github.com/nodejs/node/issues/51493
PR-URL: https://github.com/nodejs/node/pull/51569
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-02-01 14:45:38 +00:00

56 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
if (!common.hasCrypto) common.skip('missing crypto');
const assert = require('assert');
const https = require('https');
const http2 = require('http2');
(async function main() {
const server = http2.createSecureServer({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem'),
allowHTTP1: true,
});
server.on(
'request',
common.mustCall((req, res) => {
res.writeHead(200);
res.end();
})
);
server.on(
'close',
common.mustCall()
);
await new Promise((resolve) => server.listen(0, resolve));
await new Promise((resolve) =>
https.get(
`https://localhost:${server.address().port}`,
{
rejectUnauthorized: false,
headers: { connection: 'keep-alive' },
},
resolve
)
);
let serverClosed = false;
setImmediate(
common.mustCall(() => {
assert.ok(serverClosed, 'server should been closed immediately');
})
);
server.close(
common.mustSucceed(() => {
serverClosed = true;
})
);
})().then(common.mustCall());