Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix multiple set cookie calls duplicating cookies

Express/Connect has an override of res.setHeader, which has special handling for 'Set-Cookie'. This causes all already added cookies to get duplicated.

Fix by checking if we're under express/connect, and then behaving appropriately.
  • Loading branch information...
commit f8cbb1fa107e0890bd616524ffed1440fd20f54a 1 parent e0170cf
Mikko Koponen mtkopone authored
Showing with 3 additions and 1 deletion.
  1. +1 −1  lib/cookies.js
  2. +1 −0  test/express.js
  3. +1 −0  test/http.js
2  lib/cookies.js
View
@@ -38,7 +38,7 @@ Cookies.prototype = {
set: function(name, value, opts) {
var res = this.response
, req = this.request
- , headers = res.getHeader("Set-Cookie") || []
+ , headers = res.set ? [] : res.getHeader("Set-Cookie") || []
, secure = req.connection.encrypted
, cookie = new Cookie(name, value, opts)
, signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
1  test/express.js
View
@@ -56,6 +56,7 @@ http.get( options, function( res ) {
console.log( "\ncookies set:", header )
console.log( "\n============\n" )
+ assert.equal(header.length, 6)
options.path = res.headers[ "Location" ]
options.headers = { "Cookie": header.join(";") }
1  test/http.js
View
@@ -55,6 +55,7 @@ http.get( options, function( res ) {
console.log( "\ncookies set:", cookies )
console.log( "\n============\n" )
+ assert.equal(cookies.length, 6)
options.path = res.headers[ "location" ]
options.headers = { "Cookie": cookies.join(";") }
Please sign in to comment.
Something went wrong with that request. Please try again.