-
-
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
feat: add content-length headers to generated responses, via new text(...)
helper
#8371
Conversation
…` helper - closes #5749
🦋 Changeset detectedLatest commit: 4e36022 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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 approach makes sense to me
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.
Ok maybe it doesn't make sense..? This stackoverflow answer makes me kinda nervous - it seems that compression can alter the content length, and I'm not sure what bugs we might introduce if we set the uncompressed size
Ah, that's a good point. I would have assumed that if something in between SvelteKit and the user were to compress the body it would generate a new response with new headers, but I'll freely confess my ignorance here. Safest thing would be to close #5749 as wontfix but that seems unsatisfying. Am inclined to just leave this here until someone with more authority weighs in |
@dummdidumm Google's dynamic compression (CDN) requires the response to have It's was no problem to add |
If there's some library or something that compresses responses on the fly but doesn't correctly update the |
I don't think there's much value in having an So it sounds like the consensus is in favour of merging this? |
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 agree. Rereading the posted Stackoverflow answer, I noticed that the concern there is the other way around - someone's reading the response text and comparing that with the length. So this is the other end, consumer (user in the browser for our case), not producer (our server).
That said - any way we can merge another maybe bit nicer feature before releasing this? 😄 Having 1.1 just for this feels wasted. Not sure how much we care about minor version marketing at this point.
text(...)
helpertext(...)
helper
…Kit (#184) Après le passage de SvelteKit de 1.0.0 en 1.5.2, Chrome reportait des erreurs de Content-Length systématiques, qui bloquaient le reste du chargement. Le changement en cause: sveltejs/kit#8371 SvelteKit, depuis la version 1.2.0, rajoute un en-tête Content-Length à la réponse, or dans https://github.com/betagouv/dora-front/blob/571f7b9033510dec8acd362c8825650c755fc5c7/src/hooks.server.ts#L34 on réécrivait le contenu sans mettre à jour sa taille. Depuis 1.2.0, il est également possible d'accéder aux variables d'environnement directement dans le app.html, ce qui était la raison de la réécriture jusque là: sveltejs/kit#8449 Cette PR remplace donc l'ancien mécanisme de réécriture par l'officiel.
closes #5749.
This is just an idea; I don't know if it's the right one. In order to make it easier to determine response content length inside
handle
, for logging purposes, this adds a newtext(body)
helper similar to thejson(data)
helper. It returns aResponse
object with acontent-length
header, and uses it in favour ofnew Response(...)
when generating pages and other responses.One observation: it'd be nice if we could unit-test
Server
rather than having Playwright tests for the bulk of the tests inserver.test.js
. Might look into that separately.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