Skip to content

Commit

Permalink
Merge branch 'master' of github.com:senchalabs/connect
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 31, 2012
2 parents 2c6bf95 + 68dbeea commit faa7f39
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 53 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

2.6.1 / 2012-10-25
==================

* add passing of `connect.timeout()` errors to `next()`
* replace signature utils with cookie-signature module

2.6.0 / 2012-10-09
==================

Expand Down
44 changes: 22 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ http.createServer(app).listen(3000);

## Middleware

- csrf
- basicAuth
- bodyParser
- json
- multipart
- urlencoded
- cookieParser
- directory
- compress
- errorHandler
- favicon
- limit
- logger
- methodOverride
- query
- responseTime
- session
- static
- staticCache
- vhost
- subdomains
- cookieSession
- [csrf](http://www.senchalabs.org/connect/csrf.html)
- [basicAuth](http://www.senchalabs.org/connect/basicAuth.html)
- [bodyParser](http://www.senchalabs.org/connect/bodyParser.html)
- [json](http://www.senchalabs.org/connect/json.html)
- [multipart](http://www.senchalabs.org/connect/multipart.html)
- [urlencoded](http://www.senchalabs.org/connect/urlencoded.html)
- [cookieParser](http://www.senchalabs.org/connect/cookieParser.html)
- [directory](http://www.senchalabs.org/connect/directory.html)
- [compress](http://www.senchalabs.org/connect/compress.html)
- [errorHandler](http://www.senchalabs.org/connect/errorHandler.html)
- [favicon](http://www.senchalabs.org/connect/favicon.html)
- [limit](http://www.senchalabs.org/connect/limit.html)
- [logger](http://www.senchalabs.org/connect/logger.html)
- [methodOverride](http://www.senchalabs.org/connect/methodOverride.html)
- [query](http://www.senchalabs.org/connect/query.html)
- [responseTime](http://www.senchalabs.org/connect/responseTime.html)
- [session](http://www.senchalabs.org/connect/session.html)
- [static](http://www.senchalabs.org/connect/static.html)
- [staticCache](http://www.senchalabs.org/connect/staticCache.html)
- [vhost](http://www.senchalabs.org/connect/vhost.html)
- [subdomains](http://www.senchalabs.org/connect/subdomains.html)
- [cookieSession](http://www.senchalabs.org/connect/cookieSession.html)

## Running Tests

Expand Down
2 changes: 1 addition & 1 deletion lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports = module.exports = createServer;
* Framework version.
*/

exports.version = '2.6.0';
exports.version = '2.6.1';

/**
* Expose mime module.
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* - [json](json.html) application/json parser
* - [urlencoded](urlencoded.html) application/x-www-form-urlencoded parser
* - [multipart](multipart.html) multipart/form-data parser
* - [timeout](timeout.html) request timeouts
* - [cookieParser](cookieParser.html) cookie parser
* - [session](session.html) session management support with bundled MemoryStore
* - [cookieSession](cookieSession.html) cookie-based session support
Expand Down
1 change: 0 additions & 1 deletion lib/middleware/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

var utils = require('../utils')
, url = require('url')
, fs = require('fs');

// environment
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/responseTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function responseTime(){
if (res._responseTime) return next();
res._responseTime = true;

res.on('header', function(header){
res.on('header', function(){
var duration = new Date - start;
res.setHeader('X-Response-Time', duration + 'ms');
});
Expand Down
3 changes: 1 addition & 2 deletions lib/middleware/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var Session = require('./session/session')
, Store = require('./session/store')
, utils = require('./../utils')
, parse = utils.parseUrl
, crc16 = require('crc').crc16
, crypto = require('crypto');
, crc16 = require('crc').crc16;

// environment

Expand Down
4 changes: 1 addition & 3 deletions lib/middleware/session/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
* Module dependencies.
*/

var Store = require('./store')
, utils = require('../../utils')
, Session = require('./session');
var Store = require('./store');

/**
* Initialize a new `MemoryStore`.
Expand Down
5 changes: 2 additions & 3 deletions lib/middleware/session/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

var EventEmitter = require('events').EventEmitter
, Session = require('./session')
, Cookie = require('./cookie')
, utils = require('../../utils');
, Cookie = require('./cookie');

/**
* Initialize abstract `Store`.
Expand Down Expand Up @@ -83,4 +82,4 @@ Store.prototype.createSession = function(req, sess){
sess.cookie.originalMaxAge = orig;
req.session = new Session(req, sess);
return req.session;
};
};
7 changes: 2 additions & 5 deletions lib/middleware/staticCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
* Module dependencies.
*/

var http = require('http')
, utils = require('../utils')
var utils = require('../utils')
, Cache = require('../cache')
, fresh = require('fresh')
, url = require('url')
, fs = require('fs');
, fresh = require('fresh');

/**
* Static cache:
Expand Down
17 changes: 14 additions & 3 deletions lib/middleware/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
* MIT Licensed
*/

/**
* Module dependencies.
*/

var debug = require('debug')('connect:timeout');

/**
* Timeout:
*
* Times out the request in `ms`, defaulting to `5000`. The
* method `req.clearTimeout()` is added to revert this behaviour
* programmatically within your application's middleware, routes, etc.
*
* The timeout error is passed to `next()` so that you may customize
* the response behaviour. This error has the `.timeout` property as
* well as `.status == 408`.
*
* @param {Number} ms
* @return {Function}
* @api public
Expand All @@ -26,10 +36,11 @@ module.exports = function timeout(ms) {
}, ms);

req.on('timeout', function(){
if (req.headerSent) return;
if (req.headerSent) return debug('response started, cannot timeout');
var err = new Error('Request timeout');
res.statusCode = 408;
res.end('Request timeout');
err.timeout = ms;
err.status = 408;
next(err);
});

req.clearTimeout = function(){
Expand Down
2 changes: 1 addition & 1 deletion lib/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ app.handle = function(req, res, out) {
if (undefined == path) path = '/';

// skip this layer if the route doesn't match.
if (0 != path.toLowerCase().indexOf(layer.route)) return next(err);
if (0 != path.toLowerCase().indexOf(layer.route.toLowerCase())) return next(err);

c = path[layer.route.length];
if (c && '/' != c && '.' != c) return next(err);
Expand Down
4 changes: 1 addition & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
var http = require('http')
, crypto = require('crypto')
, parse = require('url').parse
, signature = require('cookie-signature')
, Path = require('path')
, fs = require('fs');
, signature = require('cookie-signature');

/**
* Extract the mime type from the given request's
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connect",
"version": "2.6.0",
"version": "2.6.1",
"description": "High performance middleware framework",
"keywords": ["framework", "web", "middleware", "connect", "rack"],
"repository": "git://github.com/senchalabs/connect.git",
Expand All @@ -12,7 +12,7 @@
"crc": "0.2.0",
"cookie": "0.0.4",
"bytes": "0.0.1",
"send": "0.0.4",
"send": "0.1.0",
"bytes": "0.1.0",
"fresh": "0.1.0",
"pause": "0.0.1",
Expand All @@ -25,5 +25,10 @@
"dox": "*"
},
"main": "index",
"engines": { "node": ">= 0.5.0" }
"engines": {
"node": ">= 0.5.0"
},
"scripts": {
"test": "make"
}
}
28 changes: 27 additions & 1 deletion test/mounting.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('app.use()', function(){
})
})

it('should be case insensitive', function(done){
it('should be case insensitive (lower-case route, mixed-case request)', function(done){
var blog = http.createServer(function(req, res){
req.url.should.equal('/');
res.end('blog');
Expand All @@ -118,4 +118,30 @@ describe('app.use()', function(){
.get('/BLog')
.expect('blog', done);
})

it('should be case insensitive (mixed-case route, lower-case request)', function(done){
var blog = http.createServer(function(req, res){
req.url.should.equal('/');
res.end('blog');
});

app.use('/BLog', blog);

app.request()
.get('/blog')
.expect('blog', done);
})

it('should be case insensitive (mixed-case route, mixed-case request)', function(done){
var blog = http.createServer(function(req, res){
req.url.should.equal('/');
res.end('blog');
});

app.use('/BLog', blog);

app.request()
.get('/blOG')
.expect('blog', done);
})
})
2 changes: 0 additions & 2 deletions test/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ describe('connect.session()', function(){
.get('/')
.set('Cookie', 'connect.sid=' + sid(res))
.end(function(res){
var id = sid(res);
res.body.should.equal('2');
done();
});
Expand Down Expand Up @@ -520,7 +519,6 @@ describe('connect.session()', function(){
.get('/')
.set('Cookie', 'connect.sid=' + sid(res))
.end(function(res){
var id = sid(res);
res.body.should.equal('2');
done();
});
Expand Down
20 changes: 18 additions & 2 deletions test/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,28 @@ describe('connect.timeout()', function(){
.get('/')
.expect(408, done);
})

it('should pass the error to next()', function(done){
var app = connect()
.use(connect.timeout(300))
.use(function(req, res){
setTimeout(function(){
res.end('Hello');
}, 400);
})
.use(function(err, req, res, next){
res.statusCode = err.status;
res.end('timeout of ' + err.timeout + 'ms exceeded');
});

app.request()
.get('/')
.expect('timeout of 300ms exceeded', done);
})
})

describe('with a partial response', function(){
it('should do nothing', function(done){
// not really ideal, but killing a socket is
// pretty dirty as well...
var app = connect()
.use(connect.timeout(300))
.use(function(req, res){
Expand Down

0 comments on commit faa7f39

Please sign in to comment.