Skip to content

download_strategy: fallback to Content-Range for file size#21431

Merged
MikeMcQuaid merged 1 commit intoHomebrew:mainfrom
shfc:fix-content-range-file-size
Jan 20, 2026
Merged

download_strategy: fallback to Content-Range for file size#21431
MikeMcQuaid merged 1 commit intoHomebrew:mainfrom
shfc:fix-content-range-file-size

Conversation

@shfc
Copy link
Copy Markdown
Contributor

@shfc shfc commented Jan 20, 2026

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

Summary

  • Extract file size from Content-Range header when Content-Length is missing
  • Add tests for Content-Range header parsing

Why

Some file storage servers return Content-Range header instead of Content-Length in HEAD responses. This causes the download progress bar to not display the total file size during concurrent downloads.

Example:

$ curl -I 'https://cdn.crabnebula.app/asset/01KFBYACJVQEXTVPRRV97DCNPV'
# HTTP/2 200
# content-range: bytes 0-191050769/191050770
# content-disposition: attachment; filename="Conductor.app.tar.gz" 
# Note: no Content-Length header

Solution

Fallback to parsing total size from Content-Range header when Content-Length is missing or zero.

According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Range, the header has these formats:

  • bytes <start>-<end>/<size> → extract <size>
  • bytes */<size> (416 response) → extract <size>
  • `bytes -/* (unknown size) → return nil

Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks and good idea!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jan 20, 2026
Merged via the queue into Homebrew:main with commit aea187c Jan 20, 2026
36 checks passed
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.

2 participants