diff --git a/README.md b/README.md index dd1ba7ac..2498c9ed 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ Session data is _not_ saved in the cookie itself, just the session ID. - `genid` - function to call to generate a new session ID. (default: uses `uid2` library) - `rolling` - forces a cookie set on every response. This resets the expiration date. (default: `false`) - `resave` - forces session to be saved even when unmodified. (default: `true`) + - `getSessionId` - a function that takes the incoming request as an argument and returns the session id. If it returns null or undefined it still falls back to using the cookie. + - Example: `function(req) { return req.query.session_id }`. - `proxy` - trust the reverse proxy when setting secure cookies (via "x-forwarded-proto" header). When set to `true`, the "x-forwarded-proto" header will be used. When set to `false`, all headers are ignored. When left unset, will use the "trust proxy" setting from express. (default: `undefined`) - `saveUninitialized` - forces a session that is "uninitialized" to be saved to the store. A session is uninitialized when it is new but not modified. This is useful for implementing login sessions, reducing server storage usage, or complying with laws that require permission before setting a cookie. (default: `true`) - `unset` - controls result of unsetting `req.session` (through `delete`, setting to `null`, etc.). This can be "keep" to keep the session in the store but ignore modifications or "destroy" to destroy the stored session. (default: `'keep'`) diff --git a/index.js b/index.js index 35ea5a84..dbdc12e0 100644 --- a/index.js +++ b/index.js @@ -310,6 +310,8 @@ function session(options){ ? saveUninitializedSession || isModified(req.session) : req.session.cookie.expires != null && isModified(req.session); } + // get the sessionID from the cookie + req.sessionID = ( options.getSessionID ? options.getSessionID(req) : null ) || unsignedCookie; // generate a session if the browser doesn't send a sessionID if (!req.sessionID) {