2015-10-29 20:53:43 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-10-06 18:24:33 +02:00
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.hasCrypto)
|
2017-05-12 07:40:13 +02:00
|
|
|
common.skip('missing crypto');
|
2017-07-01 01:29:09 +02:00
|
|
|
|
2017-10-06 18:24:33 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2015-10-29 20:53:43 +01:00
|
|
|
const https = require('https');
|
|
|
|
const tls = require('tls');
|
|
|
|
|
|
|
|
const tests = [];
|
|
|
|
|
|
|
|
const serverOptions = {
|
2017-10-06 18:24:33 +02:00
|
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
2015-10-29 20:53:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function test(fn) {
|
|
|
|
if (!tests.length) {
|
|
|
|
process.nextTick(run);
|
|
|
|
}
|
|
|
|
tests.push(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run() {
|
|
|
|
const fn = tests.shift();
|
|
|
|
if (fn) fn(run);
|
|
|
|
}
|
|
|
|
|
|
|
|
test(function serverKeepAliveTimeoutWithPipeline(cb) {
|
2017-07-16 09:00:08 +02:00
|
|
|
const server = https.createServer(
|
|
|
|
serverOptions,
|
|
|
|
common.mustCall((req, res) => {
|
|
|
|
res.end();
|
|
|
|
}, 3));
|
2017-05-30 22:06:52 +02:00
|
|
|
server.setTimeout(500, common.mustCall((socket) => {
|
|
|
|
// End this test and call `run()` for the next test (if any).
|
2015-10-29 20:53:43 +01:00
|
|
|
socket.destroy();
|
2017-05-30 22:06:52 +02:00
|
|
|
server.close();
|
|
|
|
cb();
|
|
|
|
}));
|
2015-10-29 20:53:43 +01:00
|
|
|
server.keepAliveTimeout = 50;
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const options = {
|
|
|
|
port: server.address().port,
|
|
|
|
allowHalfOpen: true,
|
|
|
|
rejectUnauthorized: false
|
|
|
|
};
|
|
|
|
const c = tls.connect(options, () => {
|
|
|
|
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
|
|
|
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
|
|
|
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
|
2017-07-16 09:00:08 +02:00
|
|
|
const server = https.createServer(serverOptions, common.mustCall(3));
|
2017-05-30 22:06:52 +02:00
|
|
|
server.setTimeout(500, common.mustCall((socket) => {
|
|
|
|
// End this test and call `run()` for the next test (if any).
|
2015-10-29 20:53:43 +01:00
|
|
|
socket.destroy();
|
2017-05-30 22:06:52 +02:00
|
|
|
server.close();
|
|
|
|
cb();
|
|
|
|
}));
|
2015-10-29 20:53:43 +01:00
|
|
|
server.keepAliveTimeout = 50;
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const options = {
|
|
|
|
port: server.address().port,
|
|
|
|
allowHalfOpen: true,
|
|
|
|
rejectUnauthorized: false
|
|
|
|
};
|
|
|
|
const c = tls.connect(options, () => {
|
|
|
|
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
|
|
|
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
|
|
|
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|