1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const { createServer } = require('http'); 6const { connect } = require('net'); 7 8// This test verifies that it is possible to disable 9// headersTimeout by setting it to zero. 10 11const server = createServer(common.mustCall((req, res) => { 12 res.writeHead(200); 13 res.end('OK'); 14})); 15 16server.headersTimeout = 0; 17 18server.once('timeout', common.mustNotCall((socket) => { 19 socket.destroy(); 20})); 21 22server.listen(0, common.mustCall(() => { 23 const client = connect(server.address().port); 24 let response = ''; 25 26 client.resume(); 27 client.write('GET / HTTP/1.1\r\nConnection: close\r\n'); 28 29 // All the timeouts below must be greater than a second, otherwise 30 // headersTimeout won't be triggered anyway as the current date is cached 31 // for a second in HTTP internals. 32 setTimeout(() => { 33 client.write('X-Crash: Ab: 456\r\n'); 34 }, common.platformTimeout(1100)).unref(); 35 36 setTimeout(() => { 37 client.write('\r\n'); 38 }, common.platformTimeout(1200)).unref(); 39 40 client.on('data', (chunk) => { 41 response += chunk.toString('utf-8'); 42 }); 43 44 client.on('end', common.mustCall(() => { 45 assert.strictEqual(response.split('\r\n').shift(), 'HTTP/1.1 200 OK'); 46 client.end(); 47 server.close(); 48 })); 49})); 50