diff options
author | 2023-02-16 20:26:00 +0100 | |
---|---|---|
committer | 2023-02-16 20:26:00 +0100 | |
commit | 9286e105684dc035f5954e6ad8e6d4a8a41dd446 (patch) | |
tree | 28df55cb7083903907ec27fcfa079940a38789dc | |
parent | 2fec4784871f2b06fd780eb4cb0bb69866c6b065 (diff) | |
download | astro-9286e105684dc035f5954e6ad8e6d4a8a41dd446.tar.gz astro-9286e105684dc035f5954e6ad8e6d4a8a41dd446.tar.zst astro-9286e105684dc035f5954e6ad8e6d4a8a41dd446.zip |
fix(cookies): Fix cookies not being all returned on Node 16 after Undici upgrade (#6265)
* fix(cookies): Fix cookies not being all returned on Node 16 after Undici upgrade
* test(cookies): Oops
-rw-r--r-- | packages/astro/src/vite-plugin-astro-server/response.ts | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/packages/astro/src/vite-plugin-astro-server/response.ts b/packages/astro/src/vite-plugin-astro-server/response.ts index 911ccf413..1a4d8ca99 100644 --- a/packages/astro/src/vite-plugin-astro-server/response.ts +++ b/packages/astro/src/vite-plugin-astro-server/response.ts @@ -55,20 +55,12 @@ export function writeHtmlResponse(res: http.ServerResponse, statusCode: number, export async function writeWebResponse(res: http.ServerResponse, webResponse: Response) { const { status, headers, body } = webResponse; - let _headers = {}; - if ('raw' in headers) { - // Node fetch allows you to get the raw headers, which includes multiples of the same type. - // This is needed because Set-Cookie *must* be called for each cookie, and can't be - // concatenated together. - type HeadersWithRaw = Headers & { - raw: () => Record<string, string[]>; - }; + const _headers = Object.fromEntries(headers.entries()); - for (const [key, value] of Object.entries((headers as HeadersWithRaw).raw())) { - res.setHeader(key, value); - } - } else { - _headers = Object.fromEntries(headers.entries()); + // Undici 5.19.1 includes a `getSetCookie` helper that returns an array of all the `set-cookies` headers. + // Previously, `headers.entries()` would already have those merged, but it seems like this isn't the case anymore, weird. + if ((headers as any)['getSetCookie']) { + _headers['set-cookie'] = (headers as any).getSetCookie(); } // Attach any set-cookie headers added via Astro.cookies.set() |