-
-
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
fix: normalize the usage of headers #3034
Conversation
🦋 Changeset detectedLatest commit: fcb6d34 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 |
I couldn't figure out how to resolve an error that was preventing me from running tests, so I haven't seen this error before. I'm guessing that the build is failing due to |
PR to address the test failure here: sveltejs/vite-plugin-svelte#225 |
@benmccann looks like the PR you mentioned is merged. Is there anything I can do to speed up the release of these changes? They address the issue that's blocking one of my projects that I must release soon. |
@illright We'll cut a new release for vite-plugin-svelte soon. There's some CI issue there as well, which will be solved by sveltejs/vite-plugin-svelte#226. Once that gets approved, we can update kit with that and rebase this PR. |
For a second thought, it's not a blocker, I can simply disable SSR for now, everything works in CSR mode. But this PR still remains very desirable for me. Just letting you know that there is no rush. In the meantime, could you please take a look at the code and let me know if everything looks alright there? |
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'm not well-versed in this area of the code so I'll leave the others to review this (Not sure if supporting the Headers
class a common thing). But at the meantime, master
has updated to the latest vite-plugin-svelte
, so a rebase should fix the CI issue.
Here's the background for this issue – I'm using |
Thank you! We can make this quite a bit simpler, I think — |
@@ -6,4 +6,12 @@ export default function (test) { | |||
const headers = response.headers(); | |||
assert.equal(headers['permissions-policy'], 'interest-cohort=()'); | |||
}); | |||
|
|||
test( | |||
'allows headers to be sent as a Headers class instead of a POJO', |
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.
this makes it sounds like you could pass either. is that correct or only a Headers instance is accepted now?
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.
This test was written by Rich, but I believe that both should be accepted, otherwise we'd make a breaking change
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.
both should be accepted, because we're just mirroring the native fetch
API (until this PR, i didn't realise you could pass a Headers
object; turns out fetch
accepts either)
@Rich-Harris are you sure about this? It seems to me that, according to the Fetch Standard, the The reason I'm concerned is that SvelteKit doesn't ship an implementation of Headers, so for Node, we cannot guarantee that the people will use an implementation that is capable of this somewhat non-standard behaviour. But I agree that this makes the code quite a bit more bloated. Maybe we could somehow expose |
Yep! It'll accept any iterable that yields string pairs: stuff = {
[Symbol.iterator]: function* () {
yield ['problems', '99'];
yield ['answer', '42'];
}
};
const headers = new Headers(stuff);
headers.get('problems'); // '99'
headers.get('answer'); // '42' That includes Headers, Map and so on. If anyone is calling fetch with a SvelteKit exposes |
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
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0This will normalize the usage of headers across the server-side
fetch
to ensure thatRecord<string, string>
,string[][]
andHeaders
are all treated correctly. Previosly, as described in #3009, whenever headers in the form ofHeaders
would come to the server-side fetch, the would be lost under a certain condition.This only fixes one of the problems in #3009, the other one about the hostnames not being compared correctly still persists.