1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5const assert = require('assert'); 6const http2 = require('http2'); 7const fs = require('fs'); 8const makeDuplexPair = require('../common/duplexpair'); 9 10{ 11 const server = http2.createServer(); 12 server.on('stream', common.mustCall((stream, headers) => { 13 stream.respondWithFile(__filename); 14 })); 15 16 const { clientSide, serverSide } = makeDuplexPair(); 17 server.emit('connection', serverSide); 18 19 const client = http2.connect('http://localhost:80', { 20 createConnection: common.mustCall(() => clientSide) 21 }); 22 23 const req = client.request(); 24 25 req.on('response', common.mustCall((headers) => { 26 assert.strictEqual(headers[':status'], 200); 27 })); 28 29 req.setEncoding('utf8'); 30 let data = ''; 31 req.on('data', (chunk) => data += chunk); 32 req.on('end', common.mustCall(() => { 33 assert.strictEqual(data, fs.readFileSync(__filename, 'utf8')); 34 clientSide.destroy(); 35 clientSide.end(); 36 })); 37 req.end(); 38} 39