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

#curl_download: default try_partial to false #13179

Merged
merged 1 commit into from Apr 25, 2022

Conversation

samford
Copy link
Member

@samford samford commented Apr 22, 2022

  • 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 style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

When its try_partial argument is true, #curl_download makes a HEAD request before downloading the file using #curl. Currently try_partial defaults to true, so any #curl_download call that doesn't explicitly specify try_partial: false will make a HEAD request first. This can potentially involve several requests if the URL redirects, so it can be a bit of unnecessary overhead when a partial download isn't needed.

Partial downloads are generally only useful when we're working with larger files, however there's currently only one place in brew where #curl_download is used and this is the case: CurlDownloadStrategy. The other #curl_download calls are fetching smaller [text] files and don't need to support partial downloads.

This PR changes the default try_partial value to false, making partial downloads opt-in rather than opt-out.


We want try_partial to continue to default to true in CurlDownloadStrategy and there are various ways to accomplish this. In this PR, I've chosen to update its #initialize method to accept a try_partial argument that defaults to true, as this value can also be used in classes that inherit from CurlDownloadStrategy (e.g., HomebrewCurlDownloadStrategy). This instance variable is passed to #curl_download in related methods, effectively maintaining the previous try_partial: true value, while also allowing this value to be overridden when necessary.

Other uses of #curl_download in brew are Formulary::FromUrlLoader#load_file and Cask::CaskLoader::FromURILoader#load, which did not provide a try_partial argument but should have been using try_partial: false. With the try_partial: false default in this PR, these calls are now fine without a try_partial argument.

The only other use of #curl_download in brew is SPDX#download_latest_license_data!. These calls were previously using try_partial: false but we can now omit this argument with the new false default (aligning with the above).

@BrewTestBot
Copy link
Member

Review period will end on 2022-04-25 at 16:12:57 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Apr 22, 2022
Library/Homebrew/download_strategy.rb Outdated Show resolved Hide resolved
When its `try_partial` argument is `true`, `#curl_download` makes a
`HEAD` request before downloading the file using `#curl`. Currently
`try_partial` defaults to `true`, so any `#curl_download` call that
doesn't explicitly specify `try_partial: false` will make a `HEAD`
request first. This can potentially involve several requests if the
URL redirects, so it can be a bit of unnecessary overhead when a
partial download isn't needed.

Partial downloads are generally only useful when we're working with
larger files, however there's currently only one place in brew where
`#curl_download` is used and this is the case:
`CurlDownloadStrategy`. The other `#curl_download` calls are fetching
smaller [text] files and don't need to support partial downloads.

This commit changes the default `try_partial` value to `false`,
making partial downloads opt-in rather than opt-out.

We want `try_partial` to continue to default to `true` in
`CurlDownloadStrategy` and there are various ways to accomplish this.
In this commit, I've chosen to update its `#initialize` method to
accept a `try_partial` argument that defaults to `true`, as this
value can also be used in classes that inherit from
`CurlDownloadStrategy` (e.g., `HomebrewCurlDownloadStrategy`). This
instance variable is passed to `#curl_download` in related methods,
effectively maintaining the previous `try_partial: true` value, while
also allowing this value to be overridden when necessary.

Other uses of `#curl_download` in brew are
`Formulary::FromUrlLoader#load_file` and
`Cask::CaskLoader::FromURILoader#load`, which did not provide a
`try_partial` argument but should have been using
`try_partial: false`. With the `try_partial: false` default in this
commit, these calls are now fine without a `try_partial` argument.

The only other use of `#curl_download` in brew is
`SPDX#download_latest_license_data!`. These calls were previously
using `try_partial: false` but we can now omit this argument with
the new `false` default (aligning with the above).
@samford samford force-pushed the curl-download-try_partial-false branch from 6190b1d to 3f7d9f8 Compare April 22, 2022 18:23
@BrewTestBot
Copy link
Member

Review period ended.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Apr 25, 2022
@samford samford merged commit 51329d9 into Homebrew:master Apr 25, 2022
@samford samford deleted the curl-download-try_partial-false branch April 25, 2022 18:25
@github-actions github-actions bot added the outdated PR was locked due to age label May 26, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants