-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Node adapter error handling in http stream: throwing async iterable shouldn't result in last HTTP/1.1 chunk being zero-length #8714
Comments
Thanks @mb21, sounds like you understand the topic quite well and we would very much appreciate a PR to resolve this. |
I mostly collected info from that linked marko issue ;-) Maybe I'll have time to take a stab at it later, but I haven't dug much in the astro code-base yet... would also be important to know whether the node server is planned to have HTTP/2 support anytime soon or not... We currently catch the throwing async iterator in our code base, put an error message at that place in the HTML, and continue to render the rest of the HTML. For that case, optimally we would have a way to signal CDNs and other caches about that, i.e. again end with a non-zero-lenght HTTP/1.1 chunk. Possible interface would be a Note: the code that currently handles this can be found here. |
@mb21 Node servers are typically run behind reverse proxies which would handle HTTPS, HTTP/2, and even HTTP/3. Would there be value to directly supporting HTTP/2? |
I think you're right that there is little benefit. This SO answer mentions "HTTP/2 server push" and some security benefits though... 🤷 |
Do you know if http/2 would mean better behavior for mid-stream failures? |
@lilnasy no, the way to signal a mid-stream failure is just different. |
Server push is deprecated. If there is a good use-case for native http/2, feel free to open an issue - I'm pretty sure it can be added very easily. |
Nice work @lilnasy ! |
Astro Info
Describe the Bug
It's great that Astro handles JS iterables in its templates and converts them to an HTTP stream, as mentioned in the docs.
However, async iterables can throw/reject, and that case isn't handled very gracefully. (Of course, the 200 status-headers have already been sent, so that's not an option.) The Astro Node adapter only supports HTTP/1.1 (if I understand correctly), so there it's actually fairly clear what to do: simply not terminate with the zero-length end chunk. Because (from marko-js/community#1):
But Astro currently returns a zero-length chunk.
To reproduce:
and run
npm run build && npm run preview
, then in another terminalcurl --raw -i http://localhost:4321
. This prints.What's the expected result?
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-v33sgm?file=src%2Fpages%2Findex.astro
(Note that the
curl
built into stackblitz somehow doesn't have a--raw
option, so you need to download the example.)The text was updated successfully, but these errors were encountered: