-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Truncated Body::len() returned when using isahc on Apple M1 #265
Comments
Thanks for filing this issue! This is definitely worth investigating in, as this should not be the case. As for the documentation note on Put another way, you should use That said, if |
Ah, I have a suspicion as to what might be happening here -- I bet the response is gzipped, in which case |
Thanks for the quick reply Stephen!
When using Safari, I get the right Here are the logs (happy to provide more if needed):
Cool! |
I have a fix for this that I will make available soon, both for the master branch and for the 0.9 series. The fix indeed is to simply not include any length in the body whenever decompression is being performed on your behalf, which seems obvious in retrospect. 😓 No one has probably noticed this before because it is likely uncommon for the server to return a |
When automatic decompression is enabled and a server returns a `Content-Length` response header for compressed content, `Body::len` was naively returning the unmodified value of `Content-Length` as the body length. This is incorrect because the `Content-Length` in this situation indicates the _compressed_ size of the body, not the uncompressed size. Since `Body::len` is supposed to be reporting the size of the body that it is returning if known, returning the uncompressed size is confusing and buggy, and can (and does) cause issues for downstream users. This fixes the issue by simply returning `None` as the body length whenever we are decompressing the response body on the user's behalf, since it is impossible for us to know the uncompressed size ahead of time. Fixes #265.
Nice, thanks for the quick fix Stephen!
What's odd is that I wasn't able to repro this issue on x86 (linux), while using the same program built with the same version of rustc. I was also able to reproduce this on a variety of websites, I couldn't find a URL that didn't reproduce the issue (I didn't try many though, happy to try with more). I wonder if the same issue is reproducible on macOS x86. |
When automatic decompression is enabled and a server returns a `Content-Length` response header for compressed content, `Body::len` was naively returning the unmodified value of `Content-Length` as the body length. This is incorrect because the `Content-Length` in this situation indicates the _compressed_ size of the body, not the uncompressed size. Since `Body::len` is supposed to be reporting the size of the body that it is returning if known, returning the uncompressed size is confusing and buggy, and can (and does) cause issues for downstream users. This fixes the issue by simply returning `None` as the body length whenever we are decompressing the response body on the user's behalf, since it is impossible for us to know the uncompressed size ahead of time. See #265. Backported from commit 5ae995f.
This should now be fixed in the 0.9.14 release! |
See http-rs/surf#270 for more context.
While the documentation stipulates that
Body::len()
should only be used as hint, it sounds surprising that the length is truncated only when using Apple M1, would it be worth investigating or is this WAI?Also as per the confusion in http-rs/surf#270, would it make sense to rename
Body::len()
to something likeBody::size_hint()
to avoid further confusion?The text was updated successfully, but these errors were encountered: