-
Notifications
You must be signed in to change notification settings - Fork 530
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
TypeError: fetch failed #1271
Comments
The error originates at Line 1868 in d94dc15
content-encoding header that is gzip .
|
It seems the actual content is not gzipped. |
Yeah, before redirect the content size is
After redirect it is gzipped, you can check with
|
Ah, I understand now. Basically we need to avoid parsing the body for the redirect. Would you like to send a PR? |
I’m not sure it’s spec compliant to not read the body? Or is a body on a redirect even allowed? |
@mcollina I'm still not familiar with the codebase, if you can fix it quickly please go ahead. Otherwise I will push a PR in a few days when I will have some free time. @ronag It seems like browsers ignore the body when status is 302. It's not even mandatory, maybe only needed for browsers which can't handle redirect? https://stackoverflow.com/questions/8059662/http-302-redirect-is-a-message-body-needed |
I think we should read the body but just ignore the content so that we can keep the connection alive. |
Btw, it's an unlikely scenario, but it's possible to have the same issue with gzip handling, when body size is small and the server has some logic to avoid gzip for small body. For example responses from API calls, such as simply |
For non-fetch undici ignores the body. Not sure yet where it goes in fetch. |
This is actually quite tricky to fix. |
Don't start prefetching the body before headers and status has been processed. Fixes: #1271
Don't start decoding the body before headers and status has been processed. Fixes: #1271
Don't start decoding the body before headers and status has been processed. Fixes: #1271
Going back to the spec: For e.g. HEAD and CONNECT the spec says:
But there is nothing along those lines for redirects. Is this a spec bug? Since Chrome does seem to disregard the body in thise case. @annevk |
Redirects can have a response body. I don't think it ever ends up being exposed though. |
* fix: lazy decode body Don't start decoding the body before headers and status has been processed. Fixes: #1271 * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup
* fix: lazy decode body Don't start decoding the body before headers and status has been processed. Fixes: nodejs#1271 * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup
* fix: lazy decode body Don't start decoding the body before headers and status has been processed. Fixes: nodejs#1271 * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup
* fix: lazy decode body Don't start decoding the body before headers and status has been processed. Fixes: nodejs#1271 * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup * fixup
Bug Description
Fetch fails with some URLs (after redirect?).
Reproducible By
let res = await fetch('https://www.luzernerzeitung.ch/kultur/literatur-im-pool-ld.2260742');
Expected Behavior
It should get the URL without any exception. The same code works just fine with 'node-fetch'.
Logs & Screenshots
Environment
macOS 11.6.4, Node v17.6.0
Additional context
The provided URL redirects and adds
?reduced=true
at the end of the URL:https://www.luzernerzeitung.ch/kultur/literatur-im-pool-ld.2260742?reduced=true
When I run the same code with this redirected URL, it works fine.
I guess a little tweak with the gzip code or redirect logic should fix this.
The text was updated successfully, but these errors were encountered: