Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] Deprecate res.clearCookie accepting options.maxAge and options.expires #5672

Merged
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unreleased

* deps: encodeurl@~2.0.0
- Removes encoding of `\`, `|`, and `^` to align better with URL spec
* Deprecate passing `options.maxAge` and `options.expires` to `res.clearCookie`
- Will be ignored in v5, clearCookie will set a cookie with an expires in the past to instruct clients to delete the cookie

4.19.2 / 2024-03-25
==========
Expand Down
9 changes: 9 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var extname = path.extname;
var mime = send.mime;
var resolve = path.resolve;
var vary = require('vary');
var deprecate = require('depd')('express');
jonchurch marked this conversation as resolved.
Show resolved Hide resolved

/**
* Response prototype.
Expand Down Expand Up @@ -822,6 +823,14 @@ res.get = function(field){
*/

res.clearCookie = function clearCookie(name, options) {
if (options && (options.maxAge || options.expires)) {
jonchurch marked this conversation as resolved.
Show resolved Hide resolved
if (options.maxAge) {
deprecate('res.clearCookie: Passing "options.maxAge" is deprecated and should be removed. Starting with the next major release of Express, this option will be ignored, as res.clearCookie will automatically set cookies to expire immediately. Please update your code to omit this option.');
jonchurch marked this conversation as resolved.
Show resolved Hide resolved
}
if (options.expires) {
deprecate('res.clearCookie: Passing "options.expires" is deprecated and should be removed. Starting with the next major release of Express, this option will be ignored, as res.clearCookie will automatically set cookies to expire immediately. Please update your code to omit this option.');
}
}
var opts = merge({ expires: new Date(1), path: '/' }, options);

return this.cookie(name, '', opts);
Expand Down
Loading