Skip to content

Commit 0415863

Browse files
author
Martijn Swaagman
authored
Merge pull request #15 from indexzero/timeout
[fix] add ability to configure timeout
2 parents 838b14b + cfdbd3a commit 0415863

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ module.exports = function createServers(options, listening) {
100100
}
101101

102102
var server = http.createServer(options.http.handler || handler),
103+
timeout = options.timeout || options.http.timeout,
103104
port = !isNaN(options.http.port) ? +options.http.port : 80, // accepts string or number
104105
args;
105106

107+
if (typeof timeout === 'number') server.setTimeout(timeout);
108+
106109
args = [server, port];
107110
if (options.http.host) {
108111
args.push(options.http.host);
@@ -126,6 +129,7 @@ module.exports = function createServers(options, listening) {
126129
var ssl = options.https,
127130
port = !isNaN(ssl.port) ? +ssl.port : 443, // accepts string or number
128131
ciphers = ssl.ciphers || CIPHERS,
132+
timeout = options.timeout || ssl.timeout,
129133
ca = ssl.ca,
130134
server,
131135
args;
@@ -165,6 +169,7 @@ module.exports = function createServers(options, listening) {
165169
log('https | listening on %d', port);
166170
server = https.createServer(finalHttpsOptions, ssl.handler || handler);
167171

172+
if (typeof timeout === 'number') server.setTimeout(timeout);
168173
args = [server, port];
169174
if (options.https.host) {
170175
args.push(options.https.host);

test/create-servers-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ test('only http, port 0', function (t) {
5151
});
5252
});
5353

54+
test('only http, timeout', function (t) {
55+
t.plan(5);
56+
var time = 3000000;
57+
createServers({
58+
log: console.log,
59+
timeout: time,
60+
http: 0,
61+
handler: fend
62+
}, function (err, servers) {
63+
console.dir(err);
64+
t.error(err);
65+
t.equals(typeof servers, 'object');
66+
t.equals(typeof servers.http, 'object');
67+
t.equals(typeof servers.http.address().port, 'number');
68+
t.equals(servers.http.timeout, time);
69+
servers.http.close();
70+
});
71+
});
5472

5573
test('only https', function (t) {
5674
t.plan(3);
@@ -71,6 +89,28 @@ test('only https', function (t) {
7189
});
7290
});
7391

92+
test('only https', function (t) {
93+
t.plan(4);
94+
var time = 4000000;
95+
createServers({
96+
log: console.log,
97+
https: {
98+
timeout: time,
99+
port: 3456,
100+
root: path.join(__dirname, 'fixtures'),
101+
cert: 'agent2-cert.pem',
102+
key: 'agent2-key.pem'
103+
},
104+
handler: fend
105+
}, function (err, servers) {
106+
t.error(err);
107+
t.equals(typeof servers, 'object');
108+
t.equals(typeof servers.https, 'object');
109+
t.equals(servers.https.timeout, time);
110+
servers.https.close();
111+
});
112+
});
113+
74114
test('absolute cert path resolution', function (t) {
75115
t.plan(3);
76116
createServers({

0 commit comments

Comments
 (0)