1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5const assert = require('assert'); 6const fixtures = require('../common/fixtures'); 7const http2 = require('http2'); 8 9const content = Buffer.alloc(1e5, 0x44); 10 11const server = http2.createSecureServer({ 12 key: fixtures.readKey('agent1-key.pem'), 13 cert: fixtures.readKey('agent1-cert.pem') 14}); 15server.on('stream', common.mustCall((stream) => { 16 stream.respond({ 17 'Content-Type': 'application/octet-stream', 18 'Content-Length': (content.length.toString() * 2), 19 'Vary': 'Accept-Encoding' 20 }); 21 22 stream.write(content); 23 stream.write(content); 24 stream.end(); 25 stream.close(); 26})); 27 28server.listen(0, common.mustCall(() => { 29 const client = http2.connect(`https://localhost:${server.address().port}`, 30 { rejectUnauthorized: false }); 31 32 const req = client.request({ ':path': '/' }); 33 req.end(); 34 35 let receivedBufferLength = 0; 36 req.on('data', common.mustCallAtLeast((buf) => { 37 receivedBufferLength += buf.length; 38 }, 1)); 39 req.on('close', common.mustCall(() => { 40 assert.strictEqual(receivedBufferLength, content.length * 2); 41 client.close(); 42 server.close(); 43 })); 44})); 45