1'use strict'; 2 3const common = require('../common.js'); 4 5const bench = common.createBenchmark(main, { 6 n: [1e3], 7 nheaders: [0, 10, 100, 1000] 8}, { flags: ['--no-warnings'] }); 9 10function main({ n, nheaders }) { 11 const http2 = require('http2'); 12 const server = http2.createServer({ 13 maxHeaderListPairs: 20000 14 }); 15 16 const headersObject = { 17 ':path': '/', 18 ':scheme': 'http', 19 'accept-encoding': 'gzip, deflate', 20 'accept-language': 'en', 21 'content-type': 'text/plain', 22 'referer': 'https://example.org/', 23 'user-agent': 'SuperBenchmarker 3000' 24 }; 25 26 for (let i = 0; i < nheaders; i++) { 27 headersObject[`foo${i}`] = `some header value ${i}`; 28 } 29 30 server.on('stream', (stream) => { 31 stream.respond(); 32 stream.end('Hi!'); 33 }); 34 server.listen(0, () => { 35 const client = http2.connect(`http://localhost:${server.address().port}/`, { 36 maxHeaderListPairs: 20000 37 }); 38 39 function doRequest(remaining) { 40 const req = client.request(headersObject); 41 req.resume(); 42 req.on('end', () => { 43 if (remaining > 0) { 44 doRequest(remaining - 1); 45 } else { 46 bench.end(n); 47 server.close(); 48 client.destroy(); 49 } 50 }); 51 } 52 53 bench.start(); 54 doRequest(n); 55 }); 56} 57