From f06be7d295a31f67758554899f250be309961827 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 5 Dec 2022 15:01:55 +0000 Subject: [PATCH] DEV: Fix multiple set-cookie through Ember-CLI proxy (#19316) The `Set-Cookie` header is an exceptional case where multiple values are allowed, and should not be joined into a single header. Because of its browser-focussed origins (where set-cookie is not visible), `fetch()` does not have a clean API for this. Instead we have to access the `raw()` data. This fixes various authentication-related issues when developing via the Ember CLI proxy. --- app/assets/javascripts/bootstrap-json/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/bootstrap-json/index.js b/app/assets/javascripts/bootstrap-json/index.js index 44414a95842..a2087fdc162 100644 --- a/app/assets/javascripts/bootstrap-json/index.js +++ b/app/assets/javascripts/bootstrap-json/index.js @@ -319,7 +319,13 @@ async function handleRequest(proxy, baseURL, req, res) { }); response.headers.forEach((value, header) => { - res.set(header, value); + if (header === "set-cookie") { + // Special handling to get array of multiple Set-Cookie header values + // per https://github.com/node-fetch/node-fetch/issues/251#issuecomment-428143940 + res.set("set-cookie", response.headers.raw()["set-cookie"]); + } else { + res.set(header, value); + } }); res.set("content-encoding", null);