-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-http2-allow-http1-upgrade-ws.js
More file actions
40 lines (32 loc) · 1.13 KB
/
test-http2-allow-http1-upgrade-ws.js
File metadata and controls
40 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Flags: --expose-internals
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
if (!common.hasCrypto) common.skip('missing crypto');
const http2 = require('http2');
const undici = require('internal/deps/undici/undici');
const WebSocketServer = require('../common/websocket-server');
(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.mustNotCall());
new WebSocketServer({ server }); // Handles websocket 'upgrade' events
await new Promise((resolve) => server.listen(0, resolve));
await new Promise((resolve, reject) => {
const ws = new WebSocket(`wss://localhost:${server.address().port}`, {
dispatcher: new undici.EnvHttpProxyAgent({
connect: { rejectUnauthorized: false },
noProxy: '*',
})
});
ws.addEventListener('open', common.mustCall(() => {
ws.close();
resolve();
}));
ws.addEventListener('error', reject);
});
server.close();
})().then(common.mustCall());