Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-timeout

Package Overview
Dependencies
Maintainers
8
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-timeout - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

14

HISTORY.md

@@ -0,1 +1,15 @@

1.8.0 / 2016-11-21
==================
* Remove un-used debug dependency
* deps: http-errors@~1.5.1
- Add `HttpError` export, for `err instanceof createError.HttpError`
- Use `setprototypeof` module to replace `__proto__` setting
- deps: inherits@2.0.3
- deps: statuses@'>= 1.3.1 < 2'
- perf: enable strict mode
* deps: ms@0.7.2
* deps: on-headers@~1.0.1
- perf: enable strict mode
1.7.0 / 2015-08-23

@@ -2,0 +16,0 @@ ==================

67

index.js

@@ -8,3 +8,3 @@ /*!

'use strict';
'use strict'

@@ -15,9 +15,14 @@ /**

var createError = require('http-errors');
var debug = require('debug')('connect:timeout');
var ms = require('ms');
var onFinished = require('on-finished');
var onHeaders = require('on-headers');
var createError = require('http-errors')
var ms = require('ms')
var onFinished = require('on-finished')
var onHeaders = require('on-headers')
/**
* Module exports.
*/
module.exports = timeout
/**
* Timeout:

@@ -33,46 +38,46 @@ *

module.exports = function timeout(time, options) {
var opts = options || {};
function timeout (time, options) {
var opts = options || {}
var delay = typeof time === 'string'
? ms(time)
: Number(time || 5000);
: Number(time || 5000)
var respond = opts.respond === undefined || opts.respond === true;
var respond = opts.respond === undefined || opts.respond === true
return function(req, res, next) {
var id = setTimeout(function(){
req.timedout = true;
req.emit('timeout', delay);
}, delay);
return function (req, res, next) {
var id = setTimeout(function () {
req.timedout = true
req.emit('timeout', delay)
}, delay)
if (respond) {
req.on('timeout', onTimeout(delay, next));
req.on('timeout', onTimeout(delay, next))
}
req.clearTimeout = function(){
clearTimeout(id);
};
req.clearTimeout = function () {
clearTimeout(id)
}
req.timedout = false;
req.timedout = false
onFinished(res, function () {
clearTimeout(id);
});
clearTimeout(id)
})
onHeaders(res, function () {
clearTimeout(id);
});
clearTimeout(id)
})
next();
};
};
next()
}
}
function onTimeout(delay, cb) {
return function(){
function onTimeout (delay, cb) {
return function () {
cb(createError(503, 'Response timeout', {
code: 'ETIMEDOUT',
timeout: delay
}));
};
}))
}
}
{
"name": "connect-timeout",
"description": "Request timeout middleware for Connect/Express",
"version": "1.7.0",
"version": "1.8.0",
"contributors": [

@@ -12,12 +12,16 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>",

"dependencies": {
"debug": "~2.2.0",
"http-errors": "~1.3.1",
"ms": "0.7.1",
"http-errors": "~1.5.1",
"ms": "0.7.2",
"on-finished": "~2.3.0",
"on-headers": "~1.0.0"
"on-headers": "~1.0.1"
},
"devDependencies": {
"istanbul": "0.3.17",
"mocha": "2.2.5",
"supertest": "1.0.1"
"eslint": "3.10.2",
"eslint-config-standard": "6.2.1",
"eslint-plugin-markdown": "1.0.0-beta.3",
"eslint-plugin-promise": "3.4.0",
"eslint-plugin-standard": "2.0.1",
"istanbul": "0.4.5",
"mocha": "2.5.3",
"supertest": "1.1.0"
},

@@ -33,2 +37,3 @@ "files": [

"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --reporter spec --bail --check-leaks test/",

@@ -35,0 +40,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",

@@ -13,2 +13,6 @@ # connect-timeout

This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```sh

@@ -71,21 +75,23 @@ $ npm install connect-timeout

```javascript
var express = require('express');
var timeout = require('connect-timeout');
var bodyParser = require('body-parser')
var cookieParser = require('cookie-parser')
var express = require('express')
var timeout = require('connect-timeout')
// example of using this top-level; note the use of haltOnTimedout
// after every middleware; it will stop the request flow on a timeout
var app = express();
app.use(timeout('5s'));
app.use(bodyParser());
app.use(haltOnTimedout);
app.use(cookieParser());
app.use(haltOnTimedout);
var app = express()
app.use(timeout('5s'))
app.use(bodyParser())
app.use(haltOnTimedout)
app.use(cookieParser())
app.use(haltOnTimedout)
// Add your routes here, etc.
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
function haltOnTimedout (req, res, next) {
if (!req.timedout) next()
}
app.listen(3000);
app.listen(3000)
```

@@ -96,26 +102,26 @@

```javascript
var express = require('express');
var bodyParser = require('body-parser');
var timeout = require('connect-timeout');
var express = require('express')
var bodyParser = require('body-parser')
var timeout = require('connect-timeout')
var app = express();
app.post('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function(req, res, next){
savePost(req.body, function(err, id){
if (err) return next(err);
if (req.timedout) return;
res.send('saved as id ' + id);
});
});
var app = express()
app.post('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function (req, res, next) {
savePost(req.body, function (err, id) {
if (err) return next(err)
if (req.timedout) return
res.send('saved as id ' + id)
})
})
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
function haltOnTimedout (req, res, next) {
if (!req.timedout) next()
}
function savePost(post, cb){
setTimeout(function(){
cb(null, ((Math.random()* 40000) >>> 0));
}, (Math.random()* 7000) >>> 0));
function savePost (post, cb) {
setTimeout(function () {
cb(null, ((Math.random() * 40000) >>> 0))
}, (Math.random() * 7000) >>> 0)
}
app.listen(3000);
app.listen(3000)
```

@@ -126,26 +132,26 @@

```javascript
var bodyParser = require('body-parser');
var connect = require('connect');
var timeout = require('connect-timeout');
var bodyParser = require('body-parser')
var connect = require('connect')
var timeout = require('connect-timeout')
var app = require('connect');
app.use('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function(req, res, next){
savePost(req.body, function(err, id){
if (err) return next(err);
if (req.timedout) return;
res.send('saved as id ' + id);
});
});
var app = connect()
app.use('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function (req, res, next) {
savePost(req.body, function (err, id) {
if (err) return next(err)
if (req.timedout) return
res.send('saved as id ' + id)
})
})
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
function haltOnTimedout (req, res, next) {
if (!req.timedout) next()
}
function savePost(post, cb){
setTimeout(function(){
cb(null, ((Math.random()* 40000) >>> 0));
}, (Math.random()* 7000) >>> 0));
function savePost (post, cb) {
setTimeout(function () {
cb(null, ((Math.random() * 40000) >>> 0))
}, (Math.random() * 7000) >>> 0)
}
app.listen(3000);
app.listen(3000)
```

@@ -152,0 +158,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc