Changed; default cookie path to "home" setting. Closes #731
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent b0e669b · Browse files · 2 files·+49 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+49 added−6 removed
- tests:+47 added−6 removed
- other:+2 added−0 removed
Provenance
- Commit
09c9452- Tree
eb40c71- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
b0e669b
2 files changed+49 added−6 removed
modified:lib/response.js+2 added
301 unmodified lines302 *303 * Options:304 *305 * - `maxAge` max-age in milliseconds, converted to `expires`306+ * - `path` defaults to the "home" setting which is typically "/"307 *308 * Examples:309 *310 * // "Remember Me" for 15 minutes10 unmodified lines321 322 res.cookie = function(name, val, options){323 options = options || {};324 if ('maxAge' in options) options.expires = new Date(Date.now() + options.maxAge);325+ options.path = options.path || this.app.set('home');326 var cookie = utils.serializeCookie(name, val, options);327 this.header('Set-Cookie', cookie);328 };329 132 unmodified linesmodified:test/response.test.js+47 added-6 removed
610 unmodified lines611 calls.should.equal(1);612 });613 },614 615- 'test #cookie()': function(){615+ 'test #cookie() path default': function(){616 var app = express.createServer();617- 617+618+ app.set('home', '/foo');619+620 app.get('/', function(req, res){621 res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });622 res.cookie('something', 'else');623 res.redirect('/');2 unmodified lines626 assert.response(app,627 { url: '/', headers: { Host: 'foo.com' }},628 function(res){629 res.headers['set-cookie']628- .should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);630+ .should.eql(['rememberme=yes; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/foo']);631 });632 },631- 632- 'test #clearCookie()': function(){633+634+ 'test #cookie() explicit path': function(){635 var app = express.createServer();636+637+ app.set('/home', '/foo');638+639+ app.get('/', function(req, res){640+ res.cookie('rememberme', 'yes', { path: '/', expires: new Date(1), httpOnly: true });641+ res.cookie('something', 'else');642+ res.redirect('/');643+ });644+645+ assert.response(app,646+ { url: '/', headers: { Host: 'foo.com' }},647+ function(res){648+ res.headers['set-cookie']649+ .should.eql(['rememberme=yes; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/']);650+ });651+ },652+653+ 'test #clearCookie() default path': function(){654+ var app = express.createServer();655+656+ app.set('home', '/foo');657+658+ app.get('/', function(req, res){659+ res.clearCookie('rememberme');660+ res.redirect('/');661+ });662 663+ assert.response(app,664+ { url: '/' },665+ function(res){666+ res.headers['set-cookie']667+ .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);668+ });669+ },670+671+ 'test #clearCookie() explicit path': function(){672+ var app = express.createServer();673+674+ app.set('home', '/bar');675+676 app.get('/', function(req, res){677 res.clearCookie('rememberme', { path: '/foo' });678 res.redirect('/');679 });4 unmodified lines684 res.headers['set-cookie']685 .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);686 });687 },647- 688+689 'test HEAD': function(){690 var app = express.createServer();691 692 app.get('/', function(req, res, next){21 unmodified lines