Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

basic cookieless session functionality #910

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var defer = typeof setImmediate === 'function'
* @param {String|Array} [options.secret] Secret for signing session ID
* @param {Object} [options.store=MemoryStore] Session store
* @param {String} [options.unset]
* @param {Boolean} [options.shouldReplaceCookieWithToken] If header should be set as Cookie or X-Access-Token
* @return {Function} middleware
* @public
*/
Expand Down Expand Up @@ -114,6 +115,10 @@ function session(options) {
// get the cookie signing secret
var secret = opts.secret

// should the header be set as token instead of cookie
var shouldReplaceCookieWithToken = opts.shouldReplaceCookieWithToken


if (typeof generateId !== 'function') {
throw new TypeError('genid option must be a function');
}
Expand Down Expand Up @@ -661,7 +666,11 @@ function setcookie(res, name, val, secret, options) {
var prev = res.getHeader('Set-Cookie') || []
var header = Array.isArray(prev) ? prev.concat(data) : [prev, data];

res.setHeader('Set-Cookie', header)
if (shouldReplaceCookieWithToken) {
res.setHeader('X-Access-Token', header)
} else {
res.setHeader('Set-Cookie', header)
}
}

/**
Expand Down