From 38da4dcac02d70f5518115bf8c2a9f3a5d4e4810 Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Tue, 10 Mar 2020 10:16:25 +0000 Subject: [PATCH 1/9] Add headers option to URLs in forumlas --- Library/Homebrew/download_strategy.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 166a1b3340..b08f7c8207 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -423,6 +423,8 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--header", meta.fetch(:header)] if meta.key?(:header) + meta.fetch(:headers).each { |h| args += ["--header", h.strip] } if meta.key?(:headers) + args end From 160b2c40d0ab182d1c15a1878c5facd67df7cf92 Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Tue, 10 Mar 2020 10:47:18 +0000 Subject: [PATCH 2/9] Add covering test for headers --- Library/Homebrew/test/download_strategies_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index e8b456d226..0d8cc669be 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -241,6 +241,21 @@ describe CurlDownloadStrategy do subject.fetch end end + + context "with headers set" do + alias_matcher :a_string_matching, :match + + let(:specs) { { headers: ["foo", "bar"]} } + + it "adds the appropriate curl args" do + expect(subject).to receive(:system_command!) { |*, args:, **| + expect(args.each_cons(2).to_a).to include(["--header", "foo"]) + expect(args.each_cons(2).to_a).to include(["--header", "bar"]) + } + + subject.fetch + end + end end describe "#cached_location" do From af3010758a901201bad0dc37e2b861f15b2d0651 Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Tue, 10 Mar 2020 10:51:20 +0000 Subject: [PATCH 3/9] appease rubocop --- Library/Homebrew/test/download_strategies_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 0d8cc669be..f24857652e 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -245,7 +245,7 @@ describe CurlDownloadStrategy do context "with headers set" do alias_matcher :a_string_matching, :match - let(:specs) { { headers: ["foo", "bar"]} } + let(:specs) { { headers: ["foo", "bar"] } } it "adds the appropriate curl args" do expect(subject).to receive(:system_command!) { |*, args:, **| From 278bba05236c0a2ca62fa686ae99a42dc8b20fcb Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Thu, 12 Mar 2020 11:32:47 +0000 Subject: [PATCH 4/9] Use concise method for both header and headers --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index b08f7c8207..14a74e75c9 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -423,7 +423,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--header", meta.fetch(:header)] if meta.key?(:header) - meta.fetch(:headers).each { |h| args += ["--header", h.strip] } if meta.key?(:headers) + args += [meta.fetch(:header), *meta.fetch(:headers)].compact.flat_map { |h| ["--header", h.strip] } args end From 0f10d7ba4081c0f71b935ba20615bf4e695eb4c4 Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Tue, 17 Mar 2020 14:32:50 +0000 Subject: [PATCH 5/9] use even more concise method for header and headers --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 14a74e75c9..5474c6fad3 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -423,7 +423,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--header", meta.fetch(:header)] if meta.key?(:header) - args += [meta.fetch(:header), *meta.fetch(:headers)].compact.flat_map { |h| ["--header", h.strip] } + args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } args end From 6d5e37654ebfba041e25b8660b0676aa9b7cbb9e Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Wed, 18 Mar 2020 14:29:36 +0000 Subject: [PATCH 6/9] Update Library/Homebrew/download_strategy.rb Co-Authored-By: Mike McQuaid --- Library/Homebrew/download_strategy.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 5474c6fad3..21ace33a38 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -421,8 +421,6 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--user", meta.fetch(:user)] if meta.key?(:user) - args += ["--header", meta.fetch(:header)] if meta.key?(:header) - args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } args From 90488ed84825189243b0a522c8b7d8dcc0f09bf4 Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Thu, 26 Mar 2020 10:40:04 +0000 Subject: [PATCH 7/9] rerun tests due to failure --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 21ace33a38..c38a6110f7 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -421,7 +421,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--user", meta.fetch(:user)] if meta.key?(:user) - args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } + args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } args end From 931e379fec26977f7a0409016632f32a8692edec Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Thu, 26 Mar 2020 10:40:21 +0000 Subject: [PATCH 8/9] remove extra space --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index c38a6110f7..21ace33a38 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -421,7 +421,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--user", meta.fetch(:user)] if meta.key?(:user) - args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } + args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } args end From 4bfed9cdb03014c0d8a331aef048aae09d2c8ebd Mon Sep 17 00:00:00 2001 From: Chris Tompkinson Date: Wed, 1 Apr 2020 15:46:28 +0100 Subject: [PATCH 9/9] flatten before compact --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 21ace33a38..0cf98d5317 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -421,7 +421,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy args += ["--user", meta.fetch(:user)] if meta.key?(:user) - args += [meta[:header], meta[:headers]].compact.flatten.flat_map { |h| ["--header", h.strip] } + args += [meta[:header], meta[:headers]].flatten.compact.flat_map { |h| ["--header", h.strip] } args end