From e1e94d3e05972decd5b715d7c322bf7c306a92ac Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Thu, 5 Jul 2012 09:38:47 -0700 Subject: [PATCH] fix cookieSession() pathname mismatch --- lib/middleware/cookieSession.js | 9 ++++----- test/cookieSession.js | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/middleware/cookieSession.js b/lib/middleware/cookieSession.js index bcd9ed5d6..6d64813f7 100644 --- a/lib/middleware/cookieSession.js +++ b/lib/middleware/cookieSession.js @@ -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) { @@ -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'); diff --git a/test/cookieSession.js b/test/cookieSession.js index 142fa72bf..d0fb545ad 100644 --- a/test/cookieSession.js +++ b/test/cookieSession.js @@ -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();