Skip to content
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 body reporting compressed length with auto decompression #267

Merged
merged 2 commits into from
Dec 9, 2020

Conversation

sagebind
Copy link
Owner

@sagebind sagebind commented Dec 8, 2020

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.

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.
@codecov
Copy link

codecov bot commented Dec 8, 2020

Codecov Report

Merging #267 (a0e9590) into master (4b8c2db) will increase coverage by 0.08%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #267      +/-   ##
==========================================
+ Coverage   72.90%   72.98%   +0.08%     
==========================================
  Files          51       51              
  Lines        2705     2717      +12     
==========================================
+ Hits         1972     1983      +11     
- Misses        733      734       +1     
Impacted Files Coverage Δ
src/client.rs 66.66% <90.90%> (+0.34%) ⬆️
tests/encoding.rs 97.91% <100.00%> (+0.13%) ⬆️
src/cookies/jar.rs 82.94% <0.00%> (+0.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b8c2db...a0e9590. Read the comment docs.

@sagebind sagebind merged commit 5ae995f into master Dec 9, 2020
@sagebind sagebind deleted the 265-compressed-body-len branch December 9, 2020 04:46
sagebind added a commit that referenced this pull request Dec 9, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Truncated Body::len() returned when using isahc on Apple M1
1 participant