Skip to content
Myr

move support for multiple `res.cookie` calls to lib/response

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Patch.js is simpler and follows upstream node.js closer as a result.

authored by Roman Shtylman · committed by Roman Shtylman · parent 143e72d · Browse files · 3 files+16 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+16 added−17 removed

  • tests:+2 added−1 removed
  • other:+14 added−16 removed

3 files+16 added−17 removed

modified:lib/patch.js+2 added-15 removed
modified:lib/response.js+12 added-1 removed
595 unmodified lines
596 options.expires = new Date(Date.now() + options.maxAge);597 options.maxAge /= 1000;598 }599 if (null == options.path) options.path = '/';600 this.set('Set-Cookie', cookie.serialize(name, String(val), options));600 var headerVal = cookie.serialize(name, String(val), options);601602 // supports multiple 'res.cookie' calls by getting previous value603 var prev = this.get('Set-Cookie');604 if (prev) {605 if (Array.isArray(prev)) {606 headerVal = prev.concat(headerVal);607 } else {608 headerVal = [prev, headerVal];609 }610 }611 this.set('Set-Cookie', headerVal);612 return this;613};614615
166 unmodified lines
modified:test/res.cookie.js+2 added-1 removed
45 unmodified lines
4647 app.use(function(req, res){48 res.cookie('name', 'tobi');49 res.cookie('age', 1);50 res.cookie('gender', '?');51 res.end();52 });5354 request(app)55 .get('/')56 .end(function(err, res){56 var val = ['name=tobi; Path=/', 'age=1; Path=/'];57 var val = ['name=tobi; Path=/', 'age=1; Path=/', 'gender=%3F; Path=/'];58 res.headers['set-cookie'].should.eql(val);59 done();60 })61 })
115 unmodified lines