Skip to content

Commit

Permalink
Added res.cookie() maxAge support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Mar 3, 2011
1 parent 5581ca2 commit 4c274c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion test/response.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ module.exports = {
res.cookie('something', 'else');
res.redirect('/');
});

assert.response(app,
{ url: '/' },
function(res){
Expand Down

0 comments on commit 4c274c5

Please sign in to comment.