Skip to content
Myr

Added res.signedCookie() and tests. Closes #880

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 7ac857a · Browse files · 2 files+64 added−1 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+64 added−1 removed

  • tests:+45 added−0 removed
  • other:+19 added−1 removed

2 files+64 added−1 removed

modified:lib/response.js+19 added-1 removed
345 unmodified lines
346 : opts);347};348349/**350 * Set a signed cookie with the given `name` and `val`.351 * See `res.cookie()` for details.352 *353 * @param {String} name354 * @param {String|Object} val355 * @param {Object} options356 * @api public357 */358359res.signedCookie = function(name, val, options){360 var secret = this.req.secret;361 if (!secret) throw new Error('connect.cookieParser("secret") required for signed cookies');362 if ('object' == typeof val) val = 'j:' + JSON.stringify(val);363 val = utils.sign(val, secret);364 return this.cookie(name, val, options);365};366367/**368 * Set cookie `name` to `val`, with the given `options`.369 *370 * Options:371 *
8 unmodified lines
380 * // save as above381 * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })382 *383 * @param {String} name366 * @param {String} val384 * @param {String|Object} val385 * @param {Options} options386 * @api public387 */388
188 unmodified lines
added:test/res.signedCookie.js+45 added