mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
fix: bump undici
to v5.20.0 (#6355)
* fix: bump `undici` to v5.20.0 * fix(cookies): Hopefully the last time we mess with undici and cookies * chore: add @astrojs/telemetry to changeset --------- Co-authored-by: Princesseuh <princssdev@gmail.com> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
parent
098341f17a
commit
5aa6580f77
5 changed files with 25 additions and 19 deletions
6
.changeset/yellow-kings-rhyme.md
Normal file
6
.changeset/yellow-kings-rhyme.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'@astrojs/webapi': patch
|
||||
'@astrojs/telemetry': patch
|
||||
---
|
||||
|
||||
Update `undici` to v5.20.0
|
|
@ -15,12 +15,14 @@ function getFromResponse(response: Response): AstroCookies | undefined {
|
|||
}
|
||||
}
|
||||
|
||||
export function* getSetCookiesFromResponse(response: Response): Generator<string, void, unknown> {
|
||||
export function* getSetCookiesFromResponse(response: Response): Generator<string, string[]> {
|
||||
const cookies = getFromResponse(response);
|
||||
if (!cookies) {
|
||||
return;
|
||||
return [];
|
||||
}
|
||||
for (const headerValue of cookies.headers()) {
|
||||
yield headerValue;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -55,19 +55,24 @@ export function writeHtmlResponse(res: http.ServerResponse, statusCode: number,
|
|||
export async function writeWebResponse(res: http.ServerResponse, webResponse: Response) {
|
||||
const { status, headers, body } = webResponse;
|
||||
|
||||
// Attach any set-cookie headers added via Astro.cookies.set()
|
||||
const setCookieHeaders = Array.from(getSetCookiesFromResponse(webResponse));
|
||||
setCookieHeaders.forEach((cookie) => {
|
||||
headers.append('set-cookie', cookie);
|
||||
});
|
||||
|
||||
const _headers = Object.fromEntries(headers.entries());
|
||||
|
||||
// Undici 5.20.0+ includes a `getSetCookie` helper that returns an array of all the `set-cookies` headers.
|
||||
// Previously, `headers.entries()` would already have these merged, but it seems like this isn't the case anymore.
|
||||
if ('getSetCookie' in headers && typeof headers.getSetCookie === 'function') {
|
||||
_headers['set-cookie'] = headers.getSetCookie();
|
||||
if (headers.has('set-cookie')) {
|
||||
if ('getSetCookie' in headers && typeof headers.getSetCookie === 'function') {
|
||||
_headers['set-cookie'] = headers.getSetCookie();
|
||||
} else {
|
||||
_headers['set-cookie'] = headers.get('set-cookie')!;
|
||||
}
|
||||
}
|
||||
|
||||
// Attach any set-cookie headers added via Astro.cookies.set()
|
||||
const setCookieHeaders = Array.from(getSetCookiesFromResponse(webResponse));
|
||||
if (setCookieHeaders.length) {
|
||||
res.setHeader('Set-Cookie', setCookieHeaders);
|
||||
}
|
||||
res.writeHead(status, _headers);
|
||||
if (body) {
|
||||
if (Symbol.for('astro.responseBody') in webResponse) {
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme",
|
||||
"dependencies": {
|
||||
"undici": "5.18.0"
|
||||
"undici": "5.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-alias": "^3.1.9",
|
||||
|
|
|
@ -3678,10 +3678,10 @@ importers:
|
|||
rollup: ^2.79.1
|
||||
tslib: ^2.4.0
|
||||
typescript: ~4.7.3
|
||||
undici: 5.18.0
|
||||
undici: 5.20.0
|
||||
urlpattern-polyfill: ^1.0.0-rc5
|
||||
dependencies:
|
||||
undici: 5.18.0
|
||||
undici: 5.20.0
|
||||
devDependencies:
|
||||
'@rollup/plugin-alias': 3.1.9_rollup@2.79.1
|
||||
'@rollup/plugin-inject': 4.0.4_rollup@2.79.1
|
||||
|
@ -14871,13 +14871,6 @@ packages:
|
|||
jiti: 1.17.0
|
||||
dev: false
|
||||
|
||||
/undici/5.18.0:
|
||||
resolution: {integrity: sha512-1iVwbhonhFytNdg0P4PqyIAXbdlVZVebtPDvuM36m66mRw4OGrCm2MYynJv/UENFLdP13J1nPVQzVE2zTs1OeA==}
|
||||
engines: {node: '>=12.18'}
|
||||
dependencies:
|
||||
busboy: 1.6.0
|
||||
dev: false
|
||||
|
||||
/undici/5.20.0:
|
||||
resolution: {integrity: sha512-J3j60dYzuo6Eevbawwp1sdg16k5Tf768bxYK4TUJRH7cBM4kFCbf3mOnM/0E3vQYXvpxITbbWmBafaDbxLDz3g==}
|
||||
engines: {node: '>=12.18'}
|
||||
|
|
Loading…
Reference in a new issue