Skip to content
Myr

Added res.cookie() maxAge support

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 5581ca2 · Browse files · 2 files+11 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−2 removed

  • tests:+1 added−1 removed
  • other:+10 added−1 removed

2 files+11 added−2 removed

modified:lib/response.js+10 added-1 removed
239 unmodified lines
240 this.cookie(name, '', { expires: new Date(1) });241};242243/**244 * Set cookie `name` to `val`.244 * Set cookie `name` to `val`, with the given `options`.245 *246 * Options:247 *248 * - `maxAge` max-age in milliseconds, converted to `expires`249 *250 * Examples:251 *252 * // "Remember Me" for 15 minutes253 * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });254 *255 * // save as above256 * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })257 *258 * @param {String} name259 * @param {String} val260 * @param {Options} options261 * @api public262 */263264res.cookie = function(name, val, options){265 options = options || {};266 if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);267 var cookie = utils.serializeCookie(name, val, options);268 this.header('Set-Cookie', cookie);269};270
104 unmodified lines
modified:test/response.test.js+1 added-1 removed
525 unmodified lines
526 res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });527 res.cookie('something', 'else');528 res.redirect('/');529 });530 530531 assert.response(app,532 { url: '/' },533 function(res){534 res.headers['set-cookie']
32 unmodified lines