1'use strict'; 2 3const common = require('../common'); 4 5if (!common.hasCrypto) 6 common.skip('missing crypto'); 7 8const fixtures = require('../common/fixtures'); 9const https = require('https'); 10const tls = require('tls'); 11 12const tests = []; 13 14const serverOptions = { 15 key: fixtures.readKey('agent1-key.pem'), 16 cert: fixtures.readKey('agent1-cert.pem') 17}; 18 19function test(fn) { 20 if (!tests.length) { 21 process.nextTick(run); 22 } 23 tests.push(fn); 24} 25 26function run() { 27 const fn = tests.shift(); 28 if (fn) fn(run); 29} 30 31test(function serverKeepAliveTimeoutWithPipeline(cb) { 32 const server = https.createServer( 33 serverOptions, 34 common.mustCall((req, res) => { 35 res.end(); 36 }, 3)); 37 server.setTimeout(common.platformTimeout(500), common.mustCall((socket) => { 38 // End this test and call `run()` for the next test (if any). 39 socket.destroy(); 40 server.close(); 41 cb(); 42 })); 43 server.keepAliveTimeout = common.platformTimeout(50); 44 server.listen(0, common.mustCall(() => { 45 const options = { 46 port: server.address().port, 47 allowHalfOpen: true, 48 rejectUnauthorized: false 49 }; 50 const c = tls.connect(options, () => { 51 c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 52 c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 53 c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 54 }); 55 })); 56}); 57 58test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) { 59 const server = https.createServer(serverOptions, common.mustCall(3)); 60 server.setTimeout(common.platformTimeout(500), common.mustCall((socket) => { 61 // End this test and call `run()` for the next test (if any). 62 socket.destroy(); 63 server.close(); 64 cb(); 65 })); 66 server.keepAliveTimeout = common.platformTimeout(50); 67 server.listen(0, common.mustCall(() => { 68 const options = { 69 port: server.address().port, 70 allowHalfOpen: true, 71 rejectUnauthorized: false 72 }; 73 const c = tls.connect(options, () => { 74 c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 75 c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 76 c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 77 }); 78 })); 79}); 80