Skip to content

Commit

Permalink
add maxage option support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 15, 2013
1 parent fd68d0f commit aa42bea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ If the _value_ is omitted, an outbound header with an expired date is used to de

If the _options_ object is provided, it will be used to generate the outbound cookie header as follows:

* `maxage`: a number representing the milliseconds from `Date.now()` for expiry
* `expires`: a `Date` object indicating the cookie's expiration date (expires at the end of session by default).
* `path`: a string indicating the path of the cookie (`/` by default).
* `domain`: a string indicating the domain of the cookie (no default).
Expand Down
2 changes: 2 additions & 0 deletions lib/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Cookie.prototype = {
toHeader: function() {
var header = this.toString()

if (this.maxage) this.expires = new Date(Date.now() + this.maxage);

if (this.path ) header += "; path=" + this.path
if (this.expires ) header += "; expires=" + this.expires.toUTCString()
if (this.domain ) header += "; domain=" + this.domain
Expand Down

0 comments on commit aa42bea

Please sign in to comment.