1'use strict'; 2const common = require('../common'); 3const fixtures = require('../common/fixtures'); 4 5if (!common.hasCrypto) 6 common.skip('missing crypto'); 7 8const assert = require('assert'); 9const https = require('https'); 10 11const serverOptions = { 12 key: fixtures.readKey('agent1-key.pem'), 13 cert: fixtures.readKey('agent1-cert.pem') 14}; 15 16let requests = 0; 17let responses = 0; 18 19const headers = {}; 20const N = 100; 21for (let i = 0; i < N; ++i) { 22 headers[`key${i}`] = i; 23} 24 25const maxAndExpected = [ // for server 26 [50, 50], 27 [1500, 102], 28 [0, N + 2], // Host and Connection 29]; 30let max = maxAndExpected[requests][0]; 31let expected = maxAndExpected[requests][1]; 32 33const server = https.createServer(serverOptions, common.mustCall((req, res) => { 34 assert.strictEqual(Object.keys(req.headers).length, expected); 35 if (++requests < maxAndExpected.length) { 36 max = maxAndExpected[requests][0]; 37 expected = maxAndExpected[requests][1]; 38 server.maxHeadersCount = max; 39 } 40 res.writeHead(200, headers); 41 res.end(); 42}, 3)); 43server.maxHeadersCount = max; 44 45server.listen(0, common.mustCall(() => { 46 const maxAndExpected = [ // for client 47 [20, 20], 48 [1200, 103], 49 [0, N + 3], // Connection, Date and Transfer-Encoding 50 ]; 51 const doRequest = common.mustCall(() => { 52 const max = maxAndExpected[responses][0]; 53 const expected = maxAndExpected[responses][1]; 54 const req = https.request({ 55 port: server.address().port, 56 headers: headers, 57 rejectUnauthorized: false 58 }, (res) => { 59 assert.strictEqual(Object.keys(res.headers).length, expected); 60 res.on('end', () => { 61 if (++responses < maxAndExpected.length) { 62 doRequest(); 63 } else { 64 server.close(); 65 } 66 }); 67 res.resume(); 68 }); 69 req.maxHeadersCount = max; 70 req.end(); 71 }, 3); 72 doRequest(); 73})); 74