0
Fork 0
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:
Emanuele Stoppa 2023-02-24 18:10:33 +00:00 committed by GitHub
parent 098341f17a
commit 5aa6580f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 19 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/webapi': patch
'@astrojs/telemetry': patch
---
Update `undici` to v5.20.0

View file

@ -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); const cookies = getFromResponse(response);
if (!cookies) { if (!cookies) {
return; return [];
} }
for (const headerValue of cookies.headers()) { for (const headerValue of cookies.headers()) {
yield headerValue; yield headerValue;
} }
return [];
} }

View file

@ -55,19 +55,24 @@ 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;
// 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()); const _headers = Object.fromEntries(headers.entries());
// Undici 5.20.0+ includes a `getSetCookie` helper that returns an array of all the `set-cookies` headers. // 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. // Previously, `headers.entries()` would already have these merged, but it seems like this isn't the case anymore.
if (headers.has('set-cookie')) {
if ('getSetCookie' in headers && typeof headers.getSetCookie === 'function') { if ('getSetCookie' in headers && typeof headers.getSetCookie === 'function') {
_headers['set-cookie'] = headers.getSetCookie(); _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); res.writeHead(status, _headers);
if (body) { if (body) {
if (Symbol.for('astro.responseBody') in webResponse) { if (Symbol.for('astro.responseBody') in webResponse) {

View file

@ -50,7 +50,7 @@
"bugs": "https://github.com/withastro/astro/issues", "bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme", "homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme",
"dependencies": { "dependencies": {
"undici": "5.18.0" "undici": "5.20.0"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-alias": "^3.1.9",

View file

@ -3678,10 +3678,10 @@ importers:
rollup: ^2.79.1 rollup: ^2.79.1
tslib: ^2.4.0 tslib: ^2.4.0
typescript: ~4.7.3 typescript: ~4.7.3
undici: 5.18.0 undici: 5.20.0
urlpattern-polyfill: ^1.0.0-rc5 urlpattern-polyfill: ^1.0.0-rc5
dependencies: dependencies:
undici: 5.18.0 undici: 5.20.0
devDependencies: devDependencies:
'@rollup/plugin-alias': 3.1.9_rollup@2.79.1 '@rollup/plugin-alias': 3.1.9_rollup@2.79.1
'@rollup/plugin-inject': 4.0.4_rollup@2.79.1 '@rollup/plugin-inject': 4.0.4_rollup@2.79.1
@ -14871,13 +14871,6 @@ packages:
jiti: 1.17.0 jiti: 1.17.0
dev: false 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: /undici/5.20.0:
resolution: {integrity: sha512-J3j60dYzuo6Eevbawwp1sdg16k5Tf768bxYK4TUJRH7cBM4kFCbf3mOnM/0E3vQYXvpxITbbWmBafaDbxLDz3g==} resolution: {integrity: sha512-J3j60dYzuo6Eevbawwp1sdg16k5Tf768bxYK4TUJRH7cBM4kFCbf3mOnM/0E3vQYXvpxITbbWmBafaDbxLDz3g==}
engines: {node: '>=12.18'} engines: {node: '>=12.18'}