Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix express cookie duplication #18

Merged
merged 2 commits into from

2 participants

@mtkopone

No description provided.

mtkopone added some commits
@mtkopone mtkopone Remove unused var e0170cf
@mtkopone mtkopone 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.
f8cbb1f
@jed jed merged commit 19985ed into from
@jed

thanks, @mtkopone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 12, 2012
  1. @mtkopone

    Remove unused var

    mtkopone authored
  2. @mtkopone

    Fix multiple set cookie calls duplicating cookies

    mtkopone authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 2 deletions.
  1. +1 −2  lib/cookies.js
  2. +1 −0  test/express.js
  3. +1 −0  test/http.js
View
3  lib/cookies.js
@@ -38,10 +38,9 @@ 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)
- , header
, signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
if (typeof headers == "string") headers = [headers]
View
1  test/express.js
@@ -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(";") }
View
1  test/http.js
@@ -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(";") }
Something went wrong with that request. Please try again.