Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ res.clearCookie = function clearCookie(name, options) {
*
* Options:
*
* - `maxAge` max-age in milliseconds, converted to `expires`
* - `maxAge` max-age in milliseconds (number), converted to `expires`
* - `signed` sign the cookie
* - `path` defaults to "/"
*
Expand Down Expand Up @@ -763,12 +763,17 @@ res.cookie = function (name, value, options) {
val = 's:' + sign(val, secret);
}

if (opts.maxAge != null) {
var maxAge = opts.maxAge - 0
if (opts.maxAge === null) {
// Treat null as "unset" (session cookie)
opts.maxAge = undefined;
}

if (typeof opts.maxAge !== 'undefined') {
var maxAge = Number(opts.maxAge);

if (!isNaN(maxAge)) {
opts.expires = new Date(Date.now() + maxAge)
opts.maxAge = Math.floor(maxAge / 1000)
if (Number.isFinite(maxAge)) {
opts.expires = new Date(Date.now() + maxAge);
opts.maxAge = Math.floor(maxAge / 1000);
}
}

Expand All @@ -777,10 +782,11 @@ res.cookie = function (name, value, options) {
}

this.append('Set-Cookie', cookie.serialize(name, String(val), opts));

return this;
};



/**
* Set the location header to `url`.
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"body-parser": "^2.2.0",
"content-disposition": "^1.0.0",
"content-type": "^1.0.5",
"cookie": "^0.7.1",
"cookie": "^1.0.2",
"cookie-signature": "^1.2.1",
"debug": "^4.4.0",
"depd": "^2.0.0",
Expand Down