1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8 9const server = http2.createServer(function(request, response) { 10 response.writeHead(200, { 'Content-Type': 'text/plain' }); 11 response.write('1\n'); 12 response.write(''); 13 response.write('2\n'); 14 response.write(''); 15 response.end('3\n'); 16 17 this.close(); 18}); 19 20server.listen(0, common.mustCall(function() { 21 const client = http2.connect(`http://localhost:${this.address().port}`); 22 const headers = { ':path': '/' }; 23 const req = client.request(headers).setEncoding('ascii'); 24 25 let res = ''; 26 27 req.on('response', common.mustCall(function(headers) { 28 assert.strictEqual(headers[':status'], 200); 29 })); 30 31 req.on('data', (chunk) => { 32 res += chunk; 33 }); 34 35 req.on('end', common.mustCall(function() { 36 assert.strictEqual(res, '1\n2\n3\n'); 37 client.close(); 38 })); 39 40 req.end(); 41})); 42