Skip to content

Commit

Permalink
fix cookieSession() pathname mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 5, 2012
1 parent 0e1fc87 commit e1e94d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/middleware/cookieSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module.exports = function cookieSession(options){

// default session
req.session = {};
var cookie = req.session.cookie = new Cookie(options.cookie);

// pathname mismatch
if (0 != req.originalUrl.indexOf(cookie.path)) return next();

// cookieParser secret
if (!options.secret && req.secret) {
Expand All @@ -76,12 +80,7 @@ module.exports = function cookieSession(options){
}
}

var cookie = req.session.cookie = new Cookie(options.cookie);

res.on('header', function(){
// pathname mismatch
if (0 != req.originalUrl.indexOf(cookie.path)) return;

// removed
if (!req.session) {
debug('clear session');
Expand Down
2 changes: 1 addition & 1 deletion test/cookieSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ describe('connect.cookieSession()', function(){
it('should not set-cookie', function(done){
var app = connect()
.use(connect.cookieParser())
.use(connect.cookieSession({ secret: 'keyboard cat',cookie: { path: '/admin' }}))
.use(connect.cookieSession({ secret: 'keyboard cat', cookie: { path: '/admin' }}))
.use(function(req, res, next){
req.session.foo = Math.random();
res.end();
Expand Down

0 comments on commit e1e94d3

Please sign in to comment.