1// Flags: --expose-internals 2'use strict'; 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const http2 = require('http2'); 8const tls = require('tls'); 9const fixtures = require('../common/fixtures'); 10 11const serverOptions = { 12 key: fixtures.readKey('agent1-key.pem'), 13 cert: fixtures.readKey('agent1-cert.pem') 14}; 15 16const server = http2.createSecureServer(serverOptions, (req, res) => { 17 res.end(); 18}); 19 20server.listen(0, '127.0.0.1', common.mustCall(() => { 21 const options = { 22 ALPNProtocols: ['h2'], 23 host: '127.0.0.1', 24 servername: 'localhost', 25 port: server.address().port, 26 rejectUnauthorized: false 27 }; 28 29 const socket = tls.connect(options, async () => { 30 socket.once('readable', () => { 31 const client = http2.connect( 32 'https://localhost:' + server.address().port, 33 { ...options, createConnection: () => socket } 34 ); 35 36 client.once('remoteSettings', common.mustCall(() => { 37 const req = client.request({ 38 ':path': '/' 39 }); 40 req.on('data', () => req.resume()); 41 req.on('end', common.mustCall(() => { 42 client.close(); 43 req.close(); 44 server.close(); 45 })); 46 req.end(); 47 })); 48 }); 49 }); 50})); 51