Skip to content
Myr

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

2 files+49 added−6 removed

modified:lib/response.js+2 added
301 unmodified lines
302 *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 minutes
10 unmodified lines
321322res.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 lines
modified:test/response.test.js+47 added-6 removed
610 unmodified lines
611 calls.should.equal(1);612 });613 },614 615 'test #cookie()': function(){615 'test #cookie() path default': function(){616 var app = express.createServer();617 617618 app.set('home', '/foo');619620 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 lines
626 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(){633634 'test #cookie() explicit path': function(){635 var app = express.createServer();636637 app.set('/home', '/foo');638639 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 });644645 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 },652653 'test #clearCookie() default path': function(){654 var app = express.createServer();655656 app.set('home', '/foo');657658 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 },670671 'test #clearCookie() explicit path': function(){672 var app = express.createServer();673674 app.set('home', '/bar');675676 app.get('/', function(req, res){677 res.clearCookie('rememberme', { path: '/foo' });678 res.redirect('/');679 });
4 unmodified lines
684 res.headers['set-cookie']685 .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);686 });687 },647 688689 'test HEAD': function(){690 var app = express.createServer();691 692 app.get('/', function(req, res, next){
21 unmodified lines