Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 4 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ContextSession {
debug('decode %j error: %s', cookie, err);
if (!(err instanceof SyntaxError)) {
// clean this cookie to ensure next request won't throw again
ctx.cookies.set(opts.key, '', opts);
ctx.cookies.set(opts.key, '', util.modifyOptsForRequest(ctx, opts));
// ctx.onerror will unset all headers, and set those specified in err
err.headers = {
'set-cookie': ctx.response.get('set-cookie'),
Expand Down Expand Up @@ -287,7 +287,7 @@ class ContextSession {
const externalKey = this.externalKey;

if (externalKey) await this.store.destroy(externalKey, { ctx });
ctx.cookies.set(key, '', opts);
ctx.cookies.set(key, '', util.modifyOptsForRequest(ctx, opts));
}

/**
Expand Down Expand Up @@ -328,7 +328,7 @@ class ContextSession {
if (opts.externalKey) {
opts.externalKey.set(this.ctx, externalKey);
} else {
this.ctx.cookies.set(key, externalKey, opts);
this.ctx.cookies.set(key, externalKey, util.modifyOptsForRequest(this.ctx, opts));
}
return;
}
Expand All @@ -338,7 +338,7 @@ class ContextSession {
json = opts.encode(json);
debug('save %s', json);

this.ctx.cookies.set(key, json, opts);
this.ctx.cookies.set(key, json, util.modifyOptsForRequest(this.ctx, opts));
}
}

Expand Down
8 changes: 8 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ module.exports = {
return crc(JSON.stringify(sess));
},

modifyOptsForRequest(ctx, opts) {
const optsCopy = Object.assign({}, opts);
if (typeof opts.domain === 'function') {
optsCopy.domain = opts.domain(ctx, opts);
}
return optsCopy;
},

CookieDateEpoch: 'Thu, 01 Jan 1970 00:00:00 GMT',
};