1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const http = require('http'); 6const { Agent } = require('_http_agent'); 7 8const agent = new Agent({ 9 keepAlive: true, 10 keepAliveMsecs: 1000, 11}); 12 13const server = http.createServer(common.mustCall((req, res) => { 14 res.end('ok'); 15})); 16 17server.listen(0, common.mustCall(() => { 18 const createConnection = agent.createConnection; 19 agent.createConnection = (options, ...args) => { 20 assert.strictEqual(options.keepAlive, true); 21 assert.strictEqual(options.keepAliveInitialDelay, agent.keepAliveMsecs); 22 return createConnection.call(agent, options, ...args); 23 }; 24 http.get({ 25 host: 'localhost', 26 port: server.address().port, 27 agent: agent, 28 path: '/' 29 }, common.mustCall((res) => { 30 // for emit end event 31 res.on('data', () => {}); 32 res.on('end', () => { 33 server.close(); 34 }); 35 })); 36})); 37