1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23require('../common'); 24const assert = require('assert'); 25const http = require('http'); 26 27let requests = 0; 28let responses = 0; 29 30const headers = {}; 31const N = 100; 32for (let i = 0; i < N; ++i) { 33 headers[`key${i}`] = i; 34} 35 36const maxAndExpected = [ // for server 37 [50, 50], 38 [1500, 102], 39 [0, N + 2], // Host and Connection 40]; 41let max = maxAndExpected[requests][0]; 42let expected = maxAndExpected[requests][1]; 43 44const server = http.createServer(function(req, res) { 45 assert.strictEqual(Object.keys(req.headers).length, expected); 46 if (++requests < maxAndExpected.length) { 47 max = maxAndExpected[requests][0]; 48 expected = maxAndExpected[requests][1]; 49 server.maxHeadersCount = max; 50 } 51 res.writeHead(200, headers); 52 res.end(); 53}); 54server.maxHeadersCount = max; 55 56server.listen(0, function() { 57 const maxAndExpected = [ // for client 58 [20, 20], 59 [1200, 103], 60 [0, N + 3], // Connection, Date and Transfer-Encoding 61 ]; 62 doRequest(); 63 64 function doRequest() { 65 const max = maxAndExpected[responses][0]; 66 const expected = maxAndExpected[responses][1]; 67 const req = http.request({ 68 port: server.address().port, 69 headers: headers 70 }, function(res) { 71 assert.strictEqual(Object.keys(res.headers).length, expected); 72 res.on('end', function() { 73 if (++responses < maxAndExpected.length) { 74 doRequest(); 75 } else { 76 server.close(); 77 } 78 }); 79 res.resume(); 80 }); 81 req.maxHeadersCount = max; 82 req.end(); 83 } 84}); 85 86process.on('exit', function() { 87 assert.strictEqual(requests, maxAndExpected.length); 88 assert.strictEqual(responses, maxAndExpected.length); 89}); 90