-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cache mechanism for request with different headers (#8754)
* Fix cache mechanism for request with different headers. * add headers to build_selector hash; * update serialize_data to include req headers; * remove data-hash if req data is an empty obj; * fix failing tests and update harcoded hash; * add new test; * update hash function to support multiple params; * fmt * simplify * remove runtime assertion, use for-of loop instead of forEach * simplify * simplify test * revert hash changes * Create silent-planes-smell.md --------- Co-authored-by: Rich Harris <[email protected]>
- Loading branch information
1 parent
32cbe07
commit c14f3ae
Showing
12 changed files
with
107 additions
and
17 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: consider headers when constructing request hash |
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
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
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
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
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
3 changes: 3 additions & 0 deletions
3
packages/kit/test/apps/basics/src/routes/load/fetch-cache-control/+page.svelte
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
<a href="/load/fetch-cache-control/load-data">load-data</a> | ||
|
||
<a href="/load/fetch-cache-control/headers-diff">headers-diff</a> | ||
|
18 changes: 18 additions & 0 deletions
18
packages/kit/test/apps/basics/src/routes/load/fetch-cache-control/headers-diff/+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,18 @@ | ||
export async function load({ fetch, url }) { | ||
const r1 = await fetch(url.pathname, { | ||
headers: { | ||
'x-foo': 'a' | ||
} | ||
}); | ||
|
||
const r2 = await fetch(url.pathname, { | ||
headers: { | ||
'x-foo': 'b' | ||
} | ||
}); | ||
|
||
return { | ||
a: r1.json(), | ||
b: r2.json() | ||
}; | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/kit/test/apps/basics/src/routes/load/fetch-cache-control/headers-diff/+page.svelte
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 @@ | ||
<script> | ||
export let data; | ||
</script> | ||
|
||
<a href="/load/fetch-cache-control">fetch-cache-control</a> | ||
|
||
<h2>{data.a.foo} / {data.b.foo}</h2> |
12 changes: 12 additions & 0 deletions
12
packages/kit/test/apps/basics/src/routes/load/fetch-cache-control/headers-diff/+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,12 @@ | ||
import { json } from '@sveltejs/kit'; | ||
|
||
/** @type {import('./$types').RequestHandler} */ | ||
export async function GET({ request, setHeaders }) { | ||
setHeaders({ | ||
'cache-control': 'public, max-age=7' | ||
}); | ||
|
||
return json({ | ||
foo: request.headers.get('x-foo') | ||
}); | ||
} |
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
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