-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't fail on immutable headers when using native fetch
According to the `fetch()`-specification, a header can have an `immutable`-guard which will throw a `TypeError` if the header is changed: https://fetch.spec.whatwg.org/#headers-class When using `fetch()`, the spec requires the response header to be `immutable` (see step 12/4): https://fetch.spec.whatwg.org/#fetch-method This is implemented in undici (used by Node.js for native fetch() under the hood): https://github.com/nodejs/undici/blob/22bdbd8c7820035276b4e876daccef513c29f5c4/lib/fetch/headers.js#L234-L239
- Loading branch information
Jakob Linskeseder
committed
Jul 11, 2023
1 parent
23d1df7
commit f4ad607
Showing
5 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
fix: gracefully handle server endpoints that return `Response`s with immutable `Headers` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/kit/test/apps/basics/src/routes/immutable-headers/+page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file will trigger the vary-header code-path in `src/runtime/server/respond.js` | ||
export function load() { | ||
return { foo: 'bar' }; | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/kit/test/apps/basics/src/routes/immutable-headers/+server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const GET = () => { | ||
const response = new Response('foo'); | ||
// this simulates immutable Response Headers, like those returned by undici | ||
Object.defineProperty(response.headers, 'append', { value: null }); | ||
Object.defineProperty(response.headers, 'set', { value: null }); | ||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters