diff --git a/HISTORY.md b/HISTORY.md index 727834eb..ffb63d71 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.13.1 / 2016-01-29 +=================== * deps: parseurl@~1.3.1 - perf: enable strict mode diff --git a/index.js b/index.js index 0de7c62f..54d8f0c0 100644 --- a/index.js +++ b/index.js @@ -5,9 +5,7 @@ * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ - 'use strict'; - /** * Module dependencies. * @private @@ -138,11 +136,10 @@ function session(options){ } // generates the new session - store.generate = function(req){ - req.sessionID = generateId(req); + store.generate = function(req, customId, fn){ + req.sessionID = customId || generateId(req); req.session = new Session(req); req.session.cookie = new Cookie(cookieOptions); - if (cookieOptions.secure === 'auto') { req.session.cookie.secure = issecure(req, trustProxy); } @@ -262,7 +259,6 @@ function session(options){ return ret; } - if (shouldDestroy(req)) { // destroy session debug('destroying'); @@ -288,11 +284,11 @@ function session(options){ req.session.touch(); if (shouldSave(req)) { + req.session.save(function onsave(err) { if (err) { defer(next, err); } - writeend(); }); @@ -312,13 +308,14 @@ function session(options){ return writetop(); } + return _end.call(res, chunk, encoding); }; // generate the session - function generate() { + function generate(customId) { store.generate(req); - originalId = req.sessionID; + originalId = customId || req.sessionID; originalHash = hash(req.session); wrapmethods(req.session); } @@ -377,6 +374,7 @@ function session(options){ return false; } + return cookieId === req.sessionID && !shouldSave(req); } @@ -387,9 +385,14 @@ function session(options){ return false; } + // in case of rolling session, always reset the cookie + if (rollingSessions) { + return true; + } + return cookieId != req.sessionID ? saveUninitializedSession || isModified(req.session) - : rollingSessions || req.session.cookie.expires != null && isModified(req.session); + :rollingSessions || req.session.cookie.expires != null && isModified(req.session); } // generate a session if the browser doesn't send a sessionID diff --git a/package.json b/package.json index 8b945f2e..b9e15281 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-session", - "version": "1.13.0", + "version": "1.13.1", "description": "Simple session middleware for Express", "author": "TJ Holowaychuk (http://tjholowaychuk.com)", "contributors": [ diff --git a/session/session.js b/session/session.js index c3c0f15a..9b2c7d3c 100644 --- a/session/session.js +++ b/session/session.js @@ -4,7 +4,6 @@ * Copyright(c) 2011 TJ Holowaychuk * MIT Licensed */ - 'use strict'; /** @@ -22,6 +21,7 @@ module.exports = Session; */ function Session(req, data) { + Object.defineProperty(this, 'req', { value: req }); Object.defineProperty(this, 'id', { value: req.sessionID }); @@ -114,12 +114,12 @@ Session.prototype.destroy = function(fn){ /** * Regenerate this request's session. * + * @param {string} customId * @param {Function} fn * @return {Session} for chaining * @api public */ - -Session.prototype.regenerate = function(fn){ - this.req.sessionStore.regenerate(this.req, fn); +Session.prototype.regenerate = function(customId, fn){ + this.req.sessionStore.regenerate(this.req, customId, fn); return this; }; diff --git a/session/store.js b/session/store.js index ca3d4a9d..6102dde1 100644 --- a/session/store.js +++ b/session/store.js @@ -1,3 +1,4 @@ + /*! * Connect - session - Store * Copyright(c) 2010 Sencha Inc. @@ -5,8 +6,6 @@ * MIT Licensed */ -'use strict'; - /** * Module dependencies. */ @@ -37,10 +36,10 @@ Store.prototype.__proto__ = EventEmitter.prototype; * @api public */ -Store.prototype.regenerate = function(req, fn){ +Store.prototype.regenerate = function(req,customId, fn){ var self = this; this.destroy(req.sessionID, function(err){ - self.generate(req); + self.generate(req, customId, fn); fn(err); }); };