fetch merges multiple "set-cookie" headers into one string

There are three separate Set-Cookie in the response header. Each one of them has different key-value pairs in it.
However, when I do response.headers.get('Set-Cookie') that merges all three Set-Cookie values into one big string and I can’t parse them by ; anymore.

fetch(url, {
    headers: {
      'Content-Type': 'application/json'
    },
    cache: 'no-cache'
  }).
  then(response => {
    headers = response.headers.get('Set-Cookie')
    console.log(headers)
    return response.json()
  })

This could be a pure javascript error but I’m not sure cause I can’t iterate through response.headers. It returns fuse objects.

Please post a complete reproduction that one could run. Unfortunately there’s not much we can help with, because we don’t know what headers your url there returns.

I added this line in the response block:

console.log(JSON.stringify(response.headers));

and tested with a random JSON API. I see that the headers are just a plain object, and I do not think that JSON objects allow several properties have the same name. You’re likely mixing something up.

Hi,

Please find it below. As you can see, there is only one “Set-Cookie” in the header and the values are merged. My-service and AWSELB should have separated by ; .

{  
   "map":{  
      "expires":[  
         "Thu, 01 Jan 1970 00:00:00 GMT"
      ],
      "x-android-selected-protocol":[  
         "http/1.1"
      ],
      "set-cookie":[  
         "JSESSIONID=node01pz39az7dsyunkzwr36xdbnpt42.node0;Path=/;My-service=6#06b8c158-86fe-446d-938e-2dc32be30589AWSELB=39C1CB2504672352592767B2CC8E871333B8A132A58C25955239B29FE2F6A83C8B7186F218837203C81AC91FC70814AFC4B05C685203728161BCE5B068789BED868EE35D81;PATH=/"
      ],
      "connection":[  
         "keep-alive"
      ],
      "x-android-response-source":[  
         "CONDITIONAL_CACHE 200"
      ],
      "x-android-sent-millis":[  
         "1504625017274"
      ],
      "content-type":[  
         "application/json"
      ],
      "cache-control":[  
         "no-cache=\"set-cookie\""
      ],
      "date":[  
         "Tue, 05 Sep 2017 15:23:35 GMT"
      ],
      "content-length":[  
         "108"
      ],
      "server":[  
         "nginx/1.10.3 (Ubuntu)"
      ],
      "null":[  
         "HTTP/1.1 200 OK"
      ],
      "x-android-received-millis":[  
         "1504625017311"
      ]
   }

Have you tried debugging what cookie string your backend sends? Is the “merging” behaviour specific to Fuse, or does, for example, a browser receive the same?

And again, please provide a complete reproduction that we could run.