1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8const { Readable } = require('stream'); 9 10const server = http2.createServer(); 11server.on('stream', common.mustCall((stream) => { 12 stream.respond({ 13 ':status': 200, 14 'content-type': 'text/html' 15 }); 16 const input = new Readable({ 17 read() { 18 this.push('test'); 19 this.push(null); 20 } 21 }); 22 input.pipe(stream); 23})); 24 25 26server.listen(0, common.mustCall(() => { 27 const port = server.address().port; 28 const client = http2.connect(`http://localhost:${port}`); 29 30 const req = client.request(); 31 32 req.on('response', common.mustCall((headers) => { 33 assert.strictEqual(headers[':status'], 200); 34 assert.strictEqual(headers['content-type'], 'text/html'); 35 })); 36 37 let data = ''; 38 39 const notCallClose = common.mustNotCall(); 40 41 setTimeout(() => { 42 req.setEncoding('utf8'); 43 req.removeListener('close', notCallClose); 44 req.on('close', common.mustCall(() => { 45 server.close(); 46 client.close(); 47 })); 48 req.on('data', common.mustCallAtLeast((d) => data += d)); 49 req.on('end', common.mustCall(() => { 50 assert.strictEqual(data, 'test'); 51 })); 52 }, common.platformTimeout(100)); 53 54 req.on('close', notCallClose); 55})); 56