Update Node_modules
This commit is contained in:
+27
-7
@@ -11,8 +11,8 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var merge = require('utils-merge')
|
||||
, cookie = require('cookie');
|
||||
var cookie = require('cookie')
|
||||
var deprecate = require('depd')('express-session')
|
||||
|
||||
/**
|
||||
* Initialize a new `Cookie` with the given `options`.
|
||||
@@ -26,10 +26,22 @@ var Cookie = module.exports = function Cookie(options) {
|
||||
this.path = '/';
|
||||
this.maxAge = null;
|
||||
this.httpOnly = true;
|
||||
if (options) merge(this, options);
|
||||
this.originalMaxAge = undefined == this.originalMaxAge
|
||||
? this.maxAge
|
||||
: this.originalMaxAge;
|
||||
|
||||
if (options) {
|
||||
if (typeof options !== 'object') {
|
||||
throw new TypeError('argument options must be a object')
|
||||
}
|
||||
|
||||
for (var key in options) {
|
||||
if (key !== 'data') {
|
||||
this[key] = options[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.originalMaxAge === undefined || this.originalMaxAge === null) {
|
||||
this.originalMaxAge = this.maxAge
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -69,7 +81,15 @@ Cookie.prototype = {
|
||||
*/
|
||||
|
||||
set maxAge(ms) {
|
||||
this.expires = 'number' == typeof ms
|
||||
if (ms && typeof ms !== 'number' && !(ms instanceof Date)) {
|
||||
throw new TypeError('maxAge must be a number or Date')
|
||||
}
|
||||
|
||||
if (ms instanceof Date) {
|
||||
deprecate('maxAge as Date; pass number of milliseconds instead')
|
||||
}
|
||||
|
||||
this.expires = typeof ms === 'number'
|
||||
? new Date(Date.now() + ms)
|
||||
: ms;
|
||||
},
|
||||
|
||||
+9
-7
@@ -171,14 +171,16 @@ function getSession(sessionId) {
|
||||
// parse
|
||||
sess = JSON.parse(sess)
|
||||
|
||||
var expires = typeof sess.cookie.expires === 'string'
|
||||
? new Date(sess.cookie.expires)
|
||||
: sess.cookie.expires
|
||||
if (sess.cookie) {
|
||||
var expires = typeof sess.cookie.expires === 'string'
|
||||
? new Date(sess.cookie.expires)
|
||||
: sess.cookie.expires
|
||||
|
||||
// destroy expired session
|
||||
if (expires && expires <= Date.now()) {
|
||||
delete this.sessions[sessionId]
|
||||
return
|
||||
// destroy expired session
|
||||
if (expires && expires <= Date.now()) {
|
||||
delete this.sessions[sessionId]
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return sess
|
||||
|
||||
+2
-1
@@ -87,7 +87,8 @@ defineMethod(Session.prototype, 'save', function save(fn) {
|
||||
|
||||
defineMethod(Session.prototype, 'reload', function reload(fn) {
|
||||
var req = this.req
|
||||
, store = this.req.sessionStore;
|
||||
var store = this.req.sessionStore
|
||||
|
||||
store.get(this.id, function(err, sess){
|
||||
if (err) return fn(err);
|
||||
if (!sess) return fn(new Error('failed to load session'));
|
||||
|
||||
+11
-3
@@ -85,10 +85,18 @@ Store.prototype.load = function(sid, fn){
|
||||
|
||||
Store.prototype.createSession = function(req, sess){
|
||||
var expires = sess.cookie.expires
|
||||
, orig = sess.cookie.originalMaxAge;
|
||||
var originalMaxAge = sess.cookie.originalMaxAge
|
||||
|
||||
sess.cookie = new Cookie(sess.cookie);
|
||||
if ('string' == typeof expires) sess.cookie.expires = new Date(expires);
|
||||
sess.cookie.originalMaxAge = orig;
|
||||
|
||||
if (typeof expires === 'string') {
|
||||
// convert expires to a Date object
|
||||
sess.cookie.expires = new Date(expires)
|
||||
}
|
||||
|
||||
// keep originalMaxAge intact
|
||||
sess.cookie.originalMaxAge = originalMaxAge
|
||||
|
||||
req.session = new Session(req, sess);
|
||||
return req.session;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user