diff -Nru node-connect-timeout-1.1.0/debian/changelog node-connect-timeout-1.3.0/debian/changelog --- node-connect-timeout-1.1.0/debian/changelog 2014-06-18 22:03:40.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/changelog 2014-10-10 14:41:28.000000000 +0000 @@ -1,3 +1,18 @@ +node-connect-timeout (1.3.0-1) unstable; urgency=medium + + * Imported Upstream version 1.3.0 + * Bump Standard-Version 3.9.6 + * Add node-on-headers as dependency + * debian/watch: fix dversionmangle + * debian/copyright: update with new author + * 0000-use_ms_from_debug.patch: import ms from debug + * debian/rules: + - update the override_dh_auto_test + - update the changelog HISTORY.md filename + * Add autopkgtest suite + + -- Leo Iannacone Fri, 10 Oct 2014 16:39:20 +0200 + node-connect-timeout (1.1.0-1) unstable; urgency=low * Initial release (Closes: #751598) diff -Nru node-connect-timeout-1.1.0/debian/control node-connect-timeout-1.3.0/debian/control --- node-connect-timeout-1.1.0/debian/control 2014-06-18 22:03:15.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/control 2014-10-10 14:35:50.000000000 +0000 @@ -8,12 +8,13 @@ , dh-buildinfo , nodejs , node-debug - , node-connect + , node-on-headers , node-should , node-mocha , node-supertest -Standards-Version: 3.9.5 +Standards-Version: 3.9.6 Homepage: https://github.com/expressjs/timeout +XS-Testsuite: autopkgtest Vcs-Git: git://anonscm.debian.org/pkg-javascript/node-connect-timeout.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-javascript/node-connect-timeout.git @@ -23,6 +24,7 @@ ${misc:Depends} , nodejs , node-debug + , node-on-headers Description: connect middleware for timing out HTTP requests - Node.js module This module allows one to set a timeout (default 5000 milliseconds) for HTTP requests. A new timeout event is added to the HTTP request instance diff -Nru node-connect-timeout-1.1.0/debian/copyright node-connect-timeout-1.3.0/debian/copyright --- node-connect-timeout-1.1.0/debian/copyright 2014-06-18 21:59:17.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/copyright 2014-10-10 14:27:45.000000000 +0000 @@ -5,6 +5,7 @@ Files: * Copyright: 2014 Jonathan Ong + 2014 Douglas Christopher Wilson License: Expat Files: debian/* diff -Nru node-connect-timeout-1.1.0/debian/patches/0000-use_ms_from_debug.patch node-connect-timeout-1.3.0/debian/patches/0000-use_ms_from_debug.patch --- node-connect-timeout-1.1.0/debian/patches/0000-use_ms_from_debug.patch 1970-01-01 00:00:00.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/patches/0000-use_ms_from_debug.patch 2014-10-10 14:26:45.000000000 +0000 @@ -0,0 +1,19 @@ +Description: import module ms from debug +Author: Leo Iannacone +Forwarded: not-needed + +--- + index.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/index.js ++++ b/index.js +@@ -10,7 +10,7 @@ + */ + + var debug = require('debug')('connect:timeout'); +-var ms = require('ms'); ++var ms = require('debug').humanize; + var onHeaders = require('on-headers'); + + /** diff -Nru node-connect-timeout-1.1.0/debian/patches/series node-connect-timeout-1.3.0/debian/patches/series --- node-connect-timeout-1.1.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/patches/series 2014-10-10 14:25:26.000000000 +0000 @@ -0,0 +1 @@ +0000-use_ms_from_debug.patch diff -Nru node-connect-timeout-1.1.0/debian/rules node-connect-timeout-1.3.0/debian/rules --- node-connect-timeout-1.1.0/debian/rules 2014-06-18 21:59:17.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/rules 2014-10-10 14:38:49.000000000 +0000 @@ -10,9 +10,9 @@ #override_dh_auto_build: override_dh_auto_test: - mocha -C --reporter spec --require should + mocha -C --reporter spec --bail --check-leaks test/ override_dh_installchangelogs: - dh_installchangelogs -k History.md + dh_installchangelogs -k HISTORY.md diff -Nru node-connect-timeout-1.1.0/debian/tests/control node-connect-timeout-1.3.0/debian/tests/control --- node-connect-timeout-1.1.0/debian/tests/control 1970-01-01 00:00:00.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/tests/control 2014-10-10 14:34:46.000000000 +0000 @@ -0,0 +1,2 @@ +Tests: require +Depends: node-connect-timeout diff -Nru node-connect-timeout-1.1.0/debian/tests/require node-connect-timeout-1.3.0/debian/tests/require --- node-connect-timeout-1.1.0/debian/tests/require 1970-01-01 00:00:00.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/tests/require 2014-10-10 14:34:46.000000000 +0000 @@ -0,0 +1,3 @@ +#!/bin/sh +set -e +nodejs -e "require('connect-timeout');" diff -Nru node-connect-timeout-1.1.0/debian/watch node-connect-timeout-1.3.0/debian/watch --- node-connect-timeout-1.1.0/debian/watch 2014-06-18 21:59:17.000000000 +0000 +++ node-connect-timeout-1.3.0/debian/watch 2014-07-05 15:20:52.000000000 +0000 @@ -1,5 +1,5 @@ version=3 opts=\ -dversionmangle=s/\?(debian|dfsg|ds|deb)\d*$//,\ +dversionmangle=s/\+(debian|dfsg|ds|deb)(\.\d+)?$//,\ filenamemangle=s/.*\/v?([\d\.-]+)\.tar\.gz/node-connect-timeout-$1.tar.gz/ \ https://github.com/expressjs/timeout/tags .*/archive/v?([\d\.]+).tar.gz diff -Nru node-connect-timeout-1.1.0/.gitignore node-connect-timeout-1.3.0/.gitignore --- node-connect-timeout-1.1.0/.gitignore 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/.gitignore 2014-09-04 04:53:44.000000000 +0000 @@ -48,6 +48,7 @@ logs results +coverage node_modules npm-debug.log diff -Nru node-connect-timeout-1.1.0/History.md node-connect-timeout-1.3.0/History.md --- node-connect-timeout-1.1.0/History.md 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/History.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -1.1.0 / 2014-04-29 -================== - - * Add `req.timedout` property - * Add `respond` option to constructor - -1.0.1 / 2014-04-28 -================== - - * Clear timer on socket destroy - * Compatible with node.js 0.8 - * deps: debug@0.8.1 - -1.0.0 / 2014-03-05 -================== - - * Genesis from `connect` diff -Nru node-connect-timeout-1.1.0/HISTORY.md node-connect-timeout-1.3.0/HISTORY.md --- node-connect-timeout-1.1.0/HISTORY.md 1970-01-01 00:00:00.000000000 +0000 +++ node-connect-timeout-1.3.0/HISTORY.md 2014-09-04 04:53:44.000000000 +0000 @@ -0,0 +1,44 @@ +1.3.0 / 2014-09-03 +================== + + * deps: debug@~2.0.0 + +1.2.2 / 2014-08-10 +================== + + * deps: on-headers@~1.0.0 + +1.2.1 / 2014-07-22 +================== + + * deps: debug@1.0.4 + +1.2.0 / 2014-07-11 +================== + + * Accept string for `time` (converted by `ms`) + * deps: debug@1.0.3 + - Add support for multiple wildcards in namespaces + +1.1.1 / 2014-06-16 +================== + + * deps: debug@1.0.2 + +1.1.0 / 2014-04-29 +================== + + * Add `req.timedout` property + * Add `respond` option to constructor + +1.0.1 / 2014-04-28 +================== + + * Clear timer on socket destroy + * Compatible with node.js 0.8 + * deps: debug@0.8.1 + +1.0.0 / 2014-03-05 +================== + + * Genesis from `connect` diff -Nru node-connect-timeout-1.1.0/index.js node-connect-timeout-1.3.0/index.js --- node-connect-timeout-1.1.0/index.js 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/index.js 2014-09-04 04:53:44.000000000 +0000 @@ -1,6 +1,7 @@ /*! - * Expressjs | Connect - timeout - * Ported from https://github.com/LearnBoost/connect-timeout + * connect-timeout + * Copyright(c) 2014 Jonathan Ong + * Copyright(c) 2014 Douglas Christopher Wilson * MIT Licensed */ @@ -9,33 +10,38 @@ */ var debug = require('debug')('connect:timeout'); +var ms = require('ms'); +var onHeaders = require('on-headers'); /** * Timeout: * * See README.md for documentation. * - * @param {Number} ms + * @param {Number} time * @param {Object} options * @return {Function} middleware * @api public */ -module.exports = function timeout(ms, options) { - ms = ms || 5000; +module.exports = function timeout(time, options) { options = options || {}; + time = typeof time === 'string' + ? ms(time) + : Number(time || 5000); + var respond = !('respond' in options) || options.respond === true; return function(req, res, next) { var destroy = req.socket.destroy; var id = setTimeout(function(){ req.timedout = true; - req.emit('timeout', ms); - }, ms); + req.emit('timeout', time); + }, time); if (respond) { - req.on('timeout', onTimeout(ms, next)); + req.on('timeout', onTimeout(time, next)); } req.clearTimeout = function(){ @@ -49,11 +55,9 @@ req.timedout = false; - var writeHead = res.writeHead; - res.writeHead = function(){ + onHeaders(res, function(){ clearTimeout(id); - writeHead.apply(res, arguments); - } + }); next(); }; @@ -66,11 +70,10 @@ return err; } -function onTimeout(ms, cb){ +function onTimeout(time, cb){ return function(){ - if (this._header) return debug('response started, cannot timeout'); var err = generateTimeoutError(); - err.timeout = ms; + err.timeout = time; cb(err); }; } diff -Nru node-connect-timeout-1.1.0/LICENSE node-connect-timeout-1.3.0/LICENSE --- node-connect-timeout-1.1.0/LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ node-connect-timeout-1.3.0/LICENSE 2014-09-04 04:53:44.000000000 +0000 @@ -0,0 +1,23 @@ +(The MIT License) + +Copyright (c) 2014 Jonathan Ong +Copyright (c) 2014 Douglas Christopher Wilson + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -Nru node-connect-timeout-1.1.0/.npmignore node-connect-timeout-1.3.0/.npmignore --- node-connect-timeout-1.1.0/.npmignore 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/.npmignore 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -test/ -.travis.yml diff -Nru node-connect-timeout-1.1.0/package.json node-connect-timeout-1.3.0/package.json --- node-connect-timeout-1.1.0/package.json 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/package.json 2014-09-04 04:53:44.000000000 +0000 @@ -1,35 +1,35 @@ { "name": "connect-timeout", "description": "timeout middleware", - "version": "1.1.0", - "author": { - "name": "Jonathan Ong", - "email": "me@jongleberry.com", - "url": "http://jongleberry.com", - "twitter": "https://twitter.com/jongleberry" - }, + "version": "1.3.0", + "contributors": [ + "Douglas Christopher Wilson ", + "Jonathan Ong (http://jongleberry.com)" + ], "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/expressjs/timeout.git" - }, - "bugs": { - "mail": "me@jongleberry.com", - "url": "https://github.com/expressjs/timeout/issues" - }, + "repository": "expressjs/timeout", "dependencies": { - "debug": "0.8.1" + "debug": "~2.0.0", + "ms": "0.6.2", + "on-headers": "~1.0.0" }, "devDependencies": { - "mocha": ">= 1.18.0 < 2.0", - "should": ">= 3.3.0 < 4.0", - "supertest": "*", - "connect": "*" - }, + "istanbul": "0.3.0", + "mocha": "~1.21.4", + "should": "~4.0.4", + "supertest": "~0.13.0" + }, + "files": [ + "LICENSE", + "HISTORY.md", + "index.js" + ], "engines": { "node": ">= 0.8" }, "scripts": { - "test": "mocha --reporter spec --require should" + "test": "mocha --reporter spec --bail --check-leaks test/", + "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --check-leaks test/" } } diff -Nru node-connect-timeout-1.1.0/README.md node-connect-timeout-1.3.0/README.md --- node-connect-timeout-1.1.0/README.md 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/README.md 2014-09-04 04:53:44.000000000 +0000 @@ -1,18 +1,28 @@ -# connect-timeout [![Build Status](https://travis-ci.org/expressjs/timeout.svg)](https://travis-ci.org/expressjs/timeout) [![NPM version](https://badge.fury.io/js/connect-timeout.svg)](http://badge.fury.io/js/connect-timeout) +# connect-timeout + +[![NPM Version][npm-image]][npm-url] +[![NPM Downloads][downloads-image]][downloads-url] +[![Build Status][travis-image]][travis-url] +[![Test Coverage][coveralls-image]][coveralls-url] +[![Gratipay][gratipay-image]][gratipay-url] Times out the request in `ms`, defaulting to `5000`. ## Install - npm install connect-timeout +```sh +$ npm install connect-timeout +``` ## API -**NOTE** This module is not recommend as a "top-level" middleware (i.e. do not recommend for use as `app.use(timeout(5000))`). +**NOTE** This module is not recommend as a "top-level" middleware (i.e. `app.use(timeout('5s'))`) unless +you take precautions to halt your own middleware processing. See [as top-level middleware](#as-top-level-middleware) +for how to use as a top-level middleware. -### timeout(ms, options) +### timeout(time, options) -Returns middleware that times out in `ms` milliseconds. On timeout, `req` will emit `"timeout"`. +Returns middleware that times out in `time` milliseconds. `time` can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme) module. On timeout, `req` will emit `"timeout"`. #### options @@ -30,6 +40,11 @@ ### as top-level middleware +Because of the way middleware processing works, this once this module passes the request +to the next middleware (which it has to do in order for you to do work), it can no longer +stop the flow, so you must take care to check if the request has timedout before you +continue to act on the request. + ```javascript var express = require('express'); var timeout = require('connect-timeout'); @@ -37,7 +52,7 @@ // 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(5000)); +app.use(timeout('5s')); app.use(bodyParser()); app.use(haltOnTimedout); app.use(cookieParser()); @@ -60,7 +75,7 @@ var timeout = require('connect-timeout'); var app = express(); -app.post('/save', timeout(5000), bodyParser.json(), haltOnTimedout, function(req, res, next){ +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; @@ -81,14 +96,15 @@ app.listen(3000); ``` -### connect 2.x +### connect ```javascript +var bodyParser = require('body-parser'); var connect = require('connect'); var timeout = require('connect-timeout'); var app = require('connect'); -app.use('/save', timeout(5000), connect.json(), haltOnTimedout, function(req, res, next){ +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; @@ -111,24 +127,15 @@ ## License -The MIT License (MIT) - -Copyright (c) 2014 Jonathan Ong me@jongleberry.com +[MIT](LICENSE) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +[npm-image]: https://img.shields.io/npm/v/connect-timeout.svg?style=flat +[npm-url]: https://npmjs.org/package/connect-timeout +[travis-image]: https://img.shields.io/travis/expressjs/timeout.svg?style=flat +[travis-url]: https://travis-ci.org/expressjs/timeout +[coveralls-image]: https://img.shields.io/coveralls/expressjs/timeout.svg?style=flat +[coveralls-url]: https://coveralls.io/r/expressjs/timeout?branch=master +[downloads-image]: https://img.shields.io/npm/dm/connect-timeout.svg?style=flat +[downloads-url]: https://npmjs.org/package/connect-timeout +[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat +[gratipay-url]: https://www.gratipay.com/dougwilson/ diff -Nru node-connect-timeout-1.1.0/test/test.js node-connect-timeout-1.3.0/test/test.js --- node-connect-timeout-1.1.0/test/test.js 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/test/test.js 2014-09-04 04:53:44.000000000 +0000 @@ -1,130 +1,123 @@ -process.env.NODE_ENV = 'test'; - -var connect = require('connect'); +var http = require('http'); var request = require('supertest'); +var should = require('should'); var timeout = require('..'); -var app = connect() - .use(timeout(300)) - .use(function(req, res){ - res.end('Hello'); - }); - describe('timeout()', function(){ + it('should have a default timeout', function (done) { + this.timeout(10000) + var server = createServer() + request(server) + .get('/') + .expect(503, done) + }) + + it('should accept millisecond timeout', function (done) { + var server = createServer(123) + request(server) + .get('/') + .expect(503, /123ms/, done) + }) + + it('should accept string timeout', function (done) { + var server = createServer('45ms') + request(server) + .get('/') + .expect(503, /45ms/, done) + }) + describe('when below the timeout', function(){ it('should do nothing', function(done){ - request(app.listen()) + var server = createServer(null, function(req, res){ + res.end('Hello') + }) + request(server) .get('/') - .expect('Hello', done); + .expect(200, 'Hello', done) }) }) describe('when above the timeout', function(){ describe('with no response made', function(){ it('should respond with 503 Request timeout', function(done){ - var app = connect() - .use(timeout(300)) - .use(function(req, res){ - setTimeout(function(){ - req.timedout.should.be.true; - res.end('Hello'); - }, 400); - }); + var server = createServer(null, null, function(req, res){ + req.timedout.should.be.true + res.end('Hello') + }) - request(app.listen()) + request(server) .get('/') - .expect(503, done); + .expect(503, done) }) it('should pass the error to next()', function(done){ - var app = connect() - .use(timeout(300)) - .use(function(req, res){ - setTimeout(function(){ - req.timedout.should.be.true; - res.end('Hello'); - }, 400); - }) - .use(function(err, req, res, next){ - res.statusCode = err.status; - res.end('timeout of ' + err.timeout + 'ms exceeded'); - }); + var server = createServer(null, null, function(req, res){ + req.timedout.should.be.true + res.end('Hello') + }) - request(app.listen()) + request(server) .get('/') - .expect('timeout of 300ms exceeded', done); + .expect('Response timeout after 100ms', done); }) }) describe('with a partial response', function(){ it('should do nothing', function(done){ - var app = connect() - .use(timeout(300)) - .use(function(req, res){ - res.write('Hello'); - setTimeout(function(){ - req.timedout.should.be.false; - res.end(' World'); - }, 400); - }); + var server = createServer(null, + function(req, res){ res.write('Hello') }, + function(req, res){ + req.timedout.should.be.false + res.end(' World') + }) - request(app.listen()) + request(server) .get('/') - .expect('Hello World', done); + .expect(200, 'Hello World', done) }) }) }) describe('options', function(){ it('can disable auto response', function(done){ - var app = connect() - .use(timeout(300, {respond: false})) - .use(function(req, res){ - setTimeout(function(){ - res.end('Timedout ' + req.timedout); - }, 400); - }); + var server = createServer({respond: false}, null, function(req, res){ + res.end('Timedout ' + req.timedout) + }) - request(app.listen()) + request(server) .get('/') - .expect('Timedout true', done); + .expect(200, 'Timedout true', done) }) }) describe('req.clearTimeout()', function(){ it('should revert this behavior', function(done){ - var app = connect() - .use(timeout(300)) - .use(function(req, res){ - req.clearTimeout(); - setTimeout(function(){ - req.timedout.should.be.false; - res.end('Hello'); - }, 400); - }); + var server = createServer(null, + function(req, res){ req.clearTimeout() }, + function(req, res){ + req.timedout.should.be.false + res.end('Hello') + }) - request(app.listen()) + request(server) .get('/') - .expect('Hello', done); + .expect(200, 'Hello', done) }) }) describe('destroy()', function(){ it('req should clear timer', function(done){ - var app = connect() - .use(timeout(100)) - .use(function(req, res){ - req.destroy(); - setTimeout(function(){ - error.code.should.equal('ECONNRESET'); - req.timedout.should.be.false; - done(); - }, 200); - }); + var server = createServer(null, + function(req, res){ req.destroy() }, + function(req, res){ + error.code.should.equal('ECONNRESET') + req.timedout.should.be.false + done() + }) var error; - request(app.listen()) + request(server) .get('/') .end(function(err){ error = err @@ -132,19 +125,16 @@ }) it('res should clear timer', function(done){ - var app = connect() - .use(timeout(100)) - .use(function(req, res){ - res.destroy(); - setTimeout(function(){ - error.code.should.equal('ECONNRESET'); - req.timedout.should.be.false; - done(); - }, 200); - }); + var server = createServer(null, + function(req, res){ res.destroy() }, + function(req, res){ + error.code.should.equal('ECONNRESET') + req.timedout.should.be.false + done() + }) var error; - request(app.listen()) + request(server) .get('/') .end(function(err){ error = err @@ -152,23 +142,70 @@ }) it('socket should clear timer', function(done){ - var app = connect() - .use(timeout(100)) - .use(function(req, res){ - req.socket.destroy(); - setTimeout(function(){ - error.code.should.equal('ECONNRESET'); - req.timedout.should.be.false; - done(); - }, 200); - }); + var server = createServer(null, + function(req, res){ req.socket.destroy() }, + function(req, res){ + error.code.should.equal('ECONNRESET') + req.timedout.should.be.false + done() + }) var error; - request(app.listen()) + request(server) .get('/') .end(function(err){ error = err }); }) }) + + describe('when request aborted', function(){ + it('should clear timeout', function(done){ + var aborted = false + var server = createServer(null, + function(req, res){ + req.on('aborted', function(){ aborted = true }) + test.abort() + }, + function(req, res){ + aborted.should.be.true + req.timedout.should.be.false + done() + }) + var error + var test = request(server).post('/') + test.write('0') + }) + }) }) + +function createServer(options, before, after) { + var _ms = 100 + + if (typeof options !== 'object') { + _ms = options + options = {} + } + + var _timeout = timeout(_ms, options) + + return http.createServer(function (req, res) { + _timeout(req, res, function (err) { + if (err) { + res.statusCode = err.status || 500 + res.end(err.message + ' after ' + err.timeout + 'ms') + return + } + + if (before) { + before(req, res) + } + + if (after) { + setTimeout(function(){ + after(req, res) + }, (_ms + 100)) + } + }) + }) +} diff -Nru node-connect-timeout-1.1.0/.travis.yml node-connect-timeout-1.3.0/.travis.yml --- node-connect-timeout-1.1.0/.travis.yml 2014-04-29 18:18:50.000000000 +0000 +++ node-connect-timeout-1.3.0/.travis.yml 2014-09-04 04:53:44.000000000 +0000 @@ -6,4 +6,6 @@ matrix: allow_failures: - node_js: "0.11" - fast_finish: true \ No newline at end of file + fast_finish: true +script: "npm run-script test-travis" +after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"