Skip to content

add parametrizable get/setcookie #420

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 3 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
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ function session(options) {
// get the save uninitialized session option
var saveUninitializedSession = opts.saveUninitialized

// get optional getcookie and setcookie custom functions
var getcookie = opts.getcookie || getcookieDefault;
var setcookie = opts.setcookie || setcookieDefault;

// get the cookie signing secret
var secret = opts.secret

Expand Down Expand Up @@ -509,7 +513,7 @@ function generateSessionId(sess) {
* @private
*/

function getcookie(req, name, secrets) {
function getcookieDefault(req, name, secrets) {
var header = req.headers.cookie;
var raw;
var val;
Expand Down Expand Up @@ -631,7 +635,7 @@ function issecure(req, trustProxy) {
* @private
*/

function setcookie(res, name, val, secret, options) {
function setcookieDefault(res, name, val, secret, options) {
var signed = 's:' + signature.sign(val, secret);
var data = cookie.serialize(name, signed, options);

Expand Down