Skip to content

Commit

Permalink
support multiple set-cookie headers in response (#8)
Browse files Browse the repository at this point in the history
Fixes and ege case with multiple set-cookie headers in a single Response

- multiple `set-cookie` headers in a single `Response` is valid
- comma delimited `set-cookie` values in a single header are invalid (or rather they will not be picked up and set by the browser)
- the res.headers interator returns the equivalent of `res.headers.get('set-cookie')` for the value, which is a comma delimited string (and thus invalid)
- this fix will use `res.headers.getAll('set-cookie')` which returns an array of strings which is a valid value in `response.setHeader` https://nodejs.org/docs/latest-v18.x/api/http.html#responsesetheadername-value
  • Loading branch information
tavvy authored Nov 27, 2022
1 parent 25cea28 commit 8490204
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ const getRequestListener = (fetchCallback: FetchCallback) => {
const contentType = res.headers.get('content-type') || ''

for (const [k, v] of res.headers) {
outgoing.setHeader(k, v)
if (k === 'set-cookie') {
outgoing.setHeader(k, res.headers.getAll(k))
} else {
outgoing.setHeader(k, v)
}
}
outgoing.statusCode = res.status

Expand Down

0 comments on commit 8490204

Please sign in to comment.