Permalink
Browse files

Added res.cookie() maxAge support

  • Loading branch information...
1 parent 5581ca2 commit 4c274c524dd588c61d022b2fa72f181481203323 @tj tj committed Mar 3, 2011
Showing with 11 additions and 2 deletions.
  1. +10 −1 lib/response.js
  2. +1 −1 test/response.test.js
View
@@ -241,20 +241,29 @@ res.clearCookie = function(name){
};
/**
- * Set cookie `name` to `val`.
+ * Set cookie `name` to `val`, with the given `options`.
+ *
+ * Options:
+ *
+ * - `maxAge` max-age in milliseconds, converted to `expires`
*
* Examples:
*
* // "Remember Me" for 15 minutes
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
*
+ * // save as above
+ * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
+ *
* @param {String} name
* @param {String} val
* @param {Options} options
* @api public
*/
res.cookie = function(name, val, options){
+ options = options || {};
+ if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);
var cookie = utils.serializeCookie(name, val, options);
this.header('Set-Cookie', cookie);
};
View
@@ -527,7 +527,7 @@ module.exports = {
res.cookie('something', 'else');
res.redirect('/');
});
-
+
assert.response(app,
{ url: '/' },
function(res){

0 comments on commit 4c274c5

Please sign in to comment.