Skip to content
Browse files

Added default options

  • Loading branch information...
1 parent f798af6 commit 8b34296bff14abee83ba115dbd208649cb5dc331 Hunter Loftis committed
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/middleware/timeout.js
View
9 lib/middleware/timeout.js
@@ -19,17 +19,22 @@
*/
module.exports = function timeout(options) {
+ options = options || {};
+ options.time = options.time || 10000;
+ options.code = options.code || 500;
+ options.throwError = options.throwError || false;
+
return function(req, res, next) {
req.socket.removeAllListeners('timeout'); // http socket auto-destroys on timeout
- req.socket.setTimeout(options.time || 10000, timed_out);
+ req.socket.setTimeout(options.time, timed_out);
function timed_out() {
if (options.throwError) {
return next(new Error('Timeout ' + at));
}
else {
- res.writeHead(options.code || 500);
+ res.writeHead(options.code);
res.end();
}
}

0 comments on commit 8b34296

Please sign in to comment.
Something went wrong with that request. Please try again.