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
This commit is contained in:
parent
2fec478487
commit
9286e10568
1 changed files with 5 additions and 13 deletions
|
@ -55,20 +55,12 @@ export function writeHtmlResponse(res: http.ServerResponse, statusCode: number,
|
||||||
export async function writeWebResponse(res: http.ServerResponse, webResponse: Response) {
|
export async function writeWebResponse(res: http.ServerResponse, webResponse: Response) {
|
||||||
const { status, headers, body } = webResponse;
|
const { status, headers, body } = webResponse;
|
||||||
|
|
||||||
let _headers = {};
|
const _headers = Object.fromEntries(headers.entries());
|
||||||
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[]>;
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const [key, value] of Object.entries((headers as HeadersWithRaw).raw())) {
|
// Undici 5.19.1 includes a `getSetCookie` helper that returns an array of all the `set-cookies` headers.
|
||||||
res.setHeader(key, value);
|
// Previously, `headers.entries()` would already have those merged, but it seems like this isn't the case anymore, weird.
|
||||||
}
|
if ((headers as any)['getSetCookie']) {
|
||||||
} else {
|
_headers['set-cookie'] = (headers as any).getSetCookie();
|
||||||
_headers = Object.fromEntries(headers.entries());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach any set-cookie headers added via Astro.cookies.set()
|
// Attach any set-cookie headers added via Astro.cookies.set()
|
||||||
|
|
Loading…
Add table
Reference in a new issue