1'use strict'; 2const common = require('../common'); 3 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const fixtures = require('../common/fixtures'); 8const http = require('http'); 9const https = require('https'); 10const http2 = require('http2'); 11const assert = require('assert'); 12const { spawnSync } = require('child_process'); 13 14// Make sure the defaults are correct. 15const servers = [ 16 http.createServer(), 17 https.createServer({ 18 key: fixtures.readKey('agent1-key.pem'), 19 cert: fixtures.readKey('agent1-cert.pem') 20 }), 21 http2.createServer() 22]; 23 24for (const server of servers) { 25 assert.strictEqual(server.timeout, 120000); 26 server.close(); 27} 28 29// Ensure that command line flag overrides the default timeout. 30const child1 = spawnSync(process.execPath, ['--http-server-default-timeout=10', 31 '-p', 'http.createServer().timeout' 32]); 33assert.strictEqual(+child1.stdout.toString().trim(), 10); 34 35// Ensure that the flag is whitelisted for NODE_OPTIONS. 36const env = Object.assign({}, process.env, { 37 NODE_OPTIONS: '--http-server-default-timeout=10' 38}); 39const child2 = spawnSync(process.execPath, 40 [ '-p', 'http.createServer().timeout'], { env }); 41assert.strictEqual(+child2.stdout.toString().trim(), 10); 42