set-cookie-parser: Incompatibility with Fetch API

The cookie parser does not recognize response returned by the Fetch API. That makes it nearly impossible to use the library in browser/Node.js/React Native environments.

The library assumes response to be a plain object with the set-cookie property. However, the Fetch Response has a different interface:

response.headers.get('Set-Cookie')
response.headers.getAll('Set-Cookie')

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I found this discussion really helpful

Oh, geze. I didn’t realize that .get() and .getAll() join all of the headers into a single comma-separated string. That’s going to be tricky to solve in the library because a header value could legitimately contain a comma. If you’re pretty sure that the headers you’re going to be working with won’t contain that string, then you can do something like this:

setCookie.parse(response.headers.get('Set-Cookie').split(/, /g));

Hey,

My understanding is that response.headers.get() returns a concatenated comma-separated string (not useful in case of Set-Cookie header). However, response.headers.getAll() should return an array of individual values. It is a bug #12846 of React Native that getAll “glues” values.