Multiple cookie support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent db60f85 · Browse files · 2 files·+29 added−12 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+29 added−12 removed
- tests:+19 added−8 removed
- other:+10 added−4 removed
Provenance
- Commit
dd07776- Tree
4e38df0- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
db60f85
2 files changed+29 added−12 removed
modified:lib/express/plugins/cookie.js+10 added-4 removed
63 unmodified lines64656667686968697071727374757677787879808081828384858687888963 unmodified lines * @api public */
cookie: function(name, val, options) { if (!val) return this.response.cookie[name] this.header('set-cookie', exports.compileCookie(name, val, options)) return val ? this.response.cookies.push(exports.compileCookie(name, val, options)) : this.cookies[name] } })
// --- Cookie
exports.Cookie = Plugin.extend({ on: { request: function(event) { event.request.response.cookie = {} event.request.response.cookies = [] if (event.request.headers.cookie) event.request.response.cookie = exports.parseCookie(event.request.headers.cookie) event.request.cookies = exports.parseCookie(event.request.headers.cookie) }, response: function(event) { if (event.response.cookies.length) event.request.header('set-cookie', event.response.cookies.join(', ')) } }})No newline at end of fileNo newline at end of filemodified:spec/spec.plugins.cookie.js+19 added-8 removed
64 unmodified lines6566676869707172737475767778798081828384858687888990919293949596787980818283848597989910064 unmodified lines }) get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar' end end describe 'response' it 'should populate Set-Cookie' get('/user', function(){ this.cookie('SID', '732423sdfs73243', { path: '/', secure: true }) return '' }) get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure' end it 'should join multiple cookies' get('/user', function(){ this.cookie('SID', '732423sdfs73243', { path: '/', secure: true }) this.cookie('foo', 'bar') return '' }) get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure, foo=bar' end end end describe 'cookie()' it 'should get request cookie values' get('/user', function(){ return this.cookie('foo') }) get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar' end it 'should populate Set-Cookie' get('/user', function(){ this.cookie('SID', '732423sdfs73243', { path: '/', secure: true }) return '' }) get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure' end end endendNo newline at end of fileNo newline at end of file