-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only include specified headers in server-side fetch requests and serialized responses #6541
Conversation
🦋 Changeset detectedLatest commit: f97dcff The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for kit-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
@@ -49,17 +49,11 @@ export function create_fetch({ event, options, state, route, prerender_default } | |||
opts.headers = new Headers(opts.headers); | |||
|
|||
// merge headers from request | |||
for (const [key, value] of event.request.headers) { | |||
if ( | |||
key !== 'authorization' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it'd be worth having a test ensuring these aren't set by default just so that if we ever decide we need to go back to a blacklist we don't accidentally add these back or to make sure we don't accidentally add these to a default whitelist in the future
I'm wondering if a static list is enough. Could there be use cases for "I want this forwarded for urls from X but not those from Y", which would hint at making this a hook somehow (which I don't know if it's possible) |
Yeah, I think a hook is the way to go. @Conduitry had a suggestion I really like, which solves the 'I want this forwarded for urls from X but not those from Y' problem while also providing a solution to #4750 — we get rid of export function handleFetch({ event, request, fetch }) {
// `event` is the underlying `RequestEvent`
// `request` is a `Request` object the normalizes the arguments to `fetch` in `load`
// `fetch` is our normal fetch logic — get data from our own routes, or delegate to undici/whatever
} This would allow us to get rid of |
Closes #5253
Closes #5195
Closes #1971
This is a topic that has been discussed a lot on this repo without an adequate resolution: when making server-side
fetch
calls within aload
function, how which (if any) of the original request headers do we include?In the interests of making things 'just work' as far as possible, we've been including almost all headers ever since #3631. But this causes its own problems, such as #5253. A PR from @johnnysprinkles (#5195) removes all header forwarding, but has sat unmerged because it depends on adding the
event
object to theload
inputs, which we definitely don't want.This PR takes a different approach (basically the one suggested by @nhunzaker in #5253 (comment)) — it allows app developers to create an allowlist of headers that should be forwarded in server-side fetches.
At the same time, we add a list of headers that should be included when we serialize the response, which means that things like
Date
don't mess up content hashing (which prevents us from responding with 304s — #1971):Questions:
content-type
inserializedResponseHeaders
to get the tests to pass, but presumably there are other sensible defaults. To some degree it doesn't matter, but it would be nice if most people didn't need to touch this optioncookie
andauthorization
headers whencredentials
is something other thanomit
?Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0