Skip to content
Myr

Added { signed: true } option to res.cookie()

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 58cfd60 · Browse files · 3 files+46 added−64 removed
This commit

State

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

Diff stats

3 files+46 added−64 removed

  • tests:+41 added−46 removed
  • other:+5 added−18 removed

3 files+46 added−64 removed

modified:lib/response.js+5 added-18 removed
439 unmodified lines
440 : opts);441};442443/**444 * Set a signed cookie with the given `name` and `val`.445 * See `res.cookie()` for details.446 *447 * @param {String} name448 * @param {String|Object} val449 * @param {Object} options450 * @api public451 */452453res.signedCookie = function(name, val, options){454 var secret = this.req.secret;455 if (!secret) throw new Error('connect.cookieParser("secret") required for signed cookies');456 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);457 val = utils.sign(val, secret);458 return this.cookie(name, val, options);459};460461/**444 * Set cookie `name` to `val`, with the given `options`.445 *446 * Options:447 *448 * - `maxAge` max-age in milliseconds, converted to `expires`449 * - `signed` sign the cookie450 * - `path` defaults to "/"451 *452 * Examples:453 *
10 unmodified lines
464 */465466res.cookie = function(name, val, options){467 options = options || {};468 var secret = this.req.secret;469 var signed = options.signed;470 if (signed && !secret) throw new Error('connect.cookieParser("secret") required for signed cookies');471 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);472 if (signed) val = utils.sign(val, secret);473 if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);474 if (null == options.path) options.path = '/';475 var cookie = utils.serializeCookie(name, val, options);476 this.set('Set-Cookie', cookie);
159 unmodified lines
modified:test/res.cookie.js+41 added
deleted:test/res.signedCookie.js-46 removed