From bcfd20e1b95078191ecbf188e32008a04baf0b3c Mon Sep 17 00:00:00 2001
From: Gordon Bleux <33967640+UiP9AV6Y@users.noreply.github.com>
Date: Sat, 7 May 2022 16:43:06 +0200
Subject: [PATCH] change cURL download behaviour for HOMEBREW_ARTIFACT_DOMAIN.
instead of prefixing and/or replacing data in URLs, the
*HOMEBREW_ARTIFACT_DOMAIN* environment variable only replaces
the bottle base URL. this causes URLs from Casks and other assets
to be no longer affected by this feature.
closes #13226
closes #13222
closes #13227
---
Library/Homebrew/download_strategy.rb | 2 +-
Library/Homebrew/test/download_strategies/curl_spec.rb | 8 +++-----
docs/Manpage.md | 2 +-
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index db09e10f0a..3e69e4881e 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -459,7 +459,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
if (domain = Homebrew::EnvConfig.artifact_domain)
- url = url.sub(%r{^(https?://#{GitHubPackages::URL_DOMAIN}/)?}o, "#{domain.chomp("/")}/")
+ url = url.sub(%r{^https?://#{GitHubPackages::URL_DOMAIN}/}o, "#{domain.chomp("/")}/")
end
output, _, _status = curl_output(
diff --git a/Library/Homebrew/test/download_strategies/curl_spec.rb b/Library/Homebrew/test/download_strategies/curl_spec.rb
index f25d03d0bc..8cd3480d7a 100644
--- a/Library/Homebrew/test/download_strategies/curl_spec.rb
+++ b/Library/Homebrew/test/download_strategies/curl_spec.rb
@@ -131,15 +131,13 @@ describe CurlDownloadStrategy do
let(:artifact_domain) { "https://mirror.example.com/oci" }
context "with an asset hosted under example.com" do
- let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) }
-
- it "prefixes the URL unchanged" do
+ it "leaves the URL unchanged" do
expect(strategy).to receive(:system_command).with(
/curl/,
- hash_including(args: array_including_cons("#{artifact_domain}/#{url}")),
+ hash_including(args: array_including_cons(url)),
)
.at_least(:once)
- .and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: []))
+ .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch
end
diff --git a/docs/Manpage.md b/docs/Manpage.md
index bde9ca5e5a..cad0417ee0 100644
--- a/docs/Manpage.md
+++ b/docs/Manpage.md
@@ -1938,7 +1938,7 @@ example, run `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just
*Default:* `native`.
- `HOMEBREW_ARTIFACT_DOMAIN`
-
Prefix all download URLs, including those for bottles, with this value. For example, `HOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080` will cause a formula with the URL `https://example.com/foo.tar.gz` to instead download from `http://localhost:8080/https://example.com/foo.tar.gz`. Bottle URLs however, have their domain replaced with this prefix. This results in e.g. `https://ghcr.io/v2/homebrew/core/gettext/manifests/0.21` to instead be downloaded from `http://localhost:8080/v2/homebrew/core/gettext/manifests/0.21`
+
Download bottle assets from with this value. For example, `HOMEBREW_ARTIFACT_DOMAIN=http://localhost:8080/mirror` will cause bottle metadata hosted at `https://ghcr.io/v2/homebrew/core/example/manifests/0.1` to instead download from `http://localhost:8080/mirror/v2/homebrew/core/example/manifests/0.1`. Other URLs such as those from Casks are *not* affected by this feature. It is intended to be used with container image mirrors/caches. For caching of arbitrary assets, see `http_proxy`.
- `HOMEBREW_AUTO_UPDATE_SECS`
Run `brew update` once every `HOMEBREW_AUTO_UPDATE_SECS` seconds before some commands, e.g. `brew install`, `brew upgrade` and `brew tap`. Alternatively, disable auto-update entirely with HOMEBREW_NO_AUTO_UPDATE.