1'use strict'; 2 3const common = require('../common'); 4const { readKey } = require('../common/fixtures'); 5 6if (!common.hasCrypto) 7 common.skip('missing crypto'); 8 9const assert = require('assert'); 10const { createServer } = require('https'); 11const { connect } = require('tls'); 12const { finished } = require('stream'); 13 14// This test validates that the 'timeout' event fires 15// after server.headersTimeout. 16 17const headers = 18 'GET / HTTP/1.1\r\n' + 19 'Host: localhost\r\n' + 20 'Agent: node\r\n'; 21 22const server = createServer({ 23 key: readKey('agent1-key.pem'), 24 cert: readKey('agent1-cert.pem'), 25 ca: readKey('ca1-cert.pem'), 26}, common.mustNotCall()); 27 28let sendCharEvery = 1000; 29 30// 60 seconds is the default 31assert.strictEqual(server.headersTimeout, 60 * 1000); 32 33// Pass a REAL env variable to shortening up the default 34// value which is 40s otherwise 35// this is useful for manual testing 36if (!process.env.REAL) { 37 sendCharEvery = common.platformTimeout(10); 38 server.headersTimeout = 2 * sendCharEvery; 39} 40 41server.once('timeout', common.mustCall((socket) => { 42 socket.destroy(); 43})); 44 45server.listen(0, common.mustCall(() => { 46 const client = connect({ 47 port: server.address().port, 48 rejectUnauthorized: false 49 }); 50 client.write(headers); 51 client.write('X-CRASH: '); 52 53 const interval = setInterval(() => { 54 client.write('a'); 55 }, sendCharEvery); 56 57 client.resume(); 58 59 finished(client, common.mustCall((err) => { 60 clearInterval(interval); 61 server.close(); 62 })); 63})); 64