fix: handle missing Content-Length header in download_file#371
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #371 +/- ##
==========================================
+ Coverage 53.31% 53.36% +0.05%
==========================================
Files 32 32
Lines 3588 3592 +4
==========================================
+ Hits 1913 1917 +4
Misses 1675 1675
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
download_file() crashes with a KeyError when the server response doesn't include a Content-Length header. This happens with chunked transfer encoding, which is common when servers apply gzip compression or when downloading from certain CDNs.
The fix uses .get() instead of direct dict access. When Content-Length is missing, the progress bar falls back to an indeterminate style instead of crashing.
This is the proper fix for the issue described in #242. That PR worked around it by forcing Accept-Encoding: identity on all downloads, which would disable compression and slow things down for everyone. This fix handles the root cause in download_file itself so all callers benefit.
Closes #242