From 8f8d69a2035a242e962063c986692a7d56b9cb6b Mon Sep 17 00:00:00 2001 From: Don Chea Date: Tue, 27 Jun 2023 09:37:22 -0400 Subject: [PATCH 1/3] cask: url stanza support for multiple headers --- Library/Homebrew/cask/url.rb | 2 +- Library/Homebrew/download_strategy.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/url.rb b/Library/Homebrew/cask/url.rb index c90cfc4898..88f316bda1 100644 --- a/Library/Homebrew/cask/url.rb +++ b/Library/Homebrew/cask/url.rb @@ -32,7 +32,7 @@ module Cask trust_cert: T.nilable(T::Boolean), cookies: T.nilable(T::Hash[String, String]), referer: T.nilable(T.any(URI::Generic, String)), - header: T.nilable(String), + header: T.nilable(T.any(String, T::Array[String])), user_agent: T.nilable(T.any(Symbol, String)), data: T.nilable(T::Hash[String, String]), only_path: T.nilable(String), diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 78632ca56a..2b409eba30 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -389,7 +389,12 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy # Merge `:header` with `:headers`. if (header = meta.delete(:header)) meta[:headers] ||= [] - meta[:headers] << header + + if header.is_a?(Array) + meta[:headers] += header + else + meta[:headers] << header + end end super From 0e9a8418fcd0b740c8c031067bfeb1f694da7c0a Mon Sep 17 00:00:00 2001 From: Don Chea Date: Tue, 27 Jun 2023 09:46:33 -0400 Subject: [PATCH 2/3] Update Cask cookbook to mention header array support --- docs/Cask-Cookbook.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Cask-Cookbook.md b/docs/Cask-Cookbook.md index 66125023aa..4f9788efb4 100644 --- a/docs/Cask-Cookbook.md +++ b/docs/Cask-Cookbook.md @@ -1079,7 +1079,7 @@ When a plain URL string is insufficient to fetch a file, additional information | `using:` | the symbol `:post` is the only legal value | `cookies:` | hash of cookies to be set in the download request | `referer:` | string holding the URL to set as referer in the download request -| `header:` | string holding the header to set for the download request +| `header:` | string or array of strings holding the header(s) to set for the download request | `user_agent:` | string holding the user agent to set for the download request. Can also be set to the symbol `:fake`, which will use a generic browser-like user agent string. We prefer `:fake` when the server does not require a specific user agent. | `data:` | hash of parameters to be set in the POST request @@ -1087,7 +1087,7 @@ Example of using `cookies:`: [oracle-jdk-javadoc.rb](https://github.com/Homebrew Example of using `referer:`: [firealpaca.rb](https://github.com/Homebrew/homebrew-cask/blob/37f434b99f51259e642793d65b7490540b71dc21/Casks/firealpaca.rb#L5-L6) -Example of using `header:`: [issue-325182724](https://github.com/Homebrew/brew/pull/6545#issue-325182724) +Example of using `header:`: [issue-325182724](https://github.com/Homebrew/brew/pull/6545#issue-325182724) [issue-15590](https://github.com/Homebrew/brew/issues/15590) #### When URL and Homepage Domains Differ, Add `verified:` From 907a9238c252ef1f0b220e2b469e0a6aa150901c Mon Sep 17 00:00:00 2001 From: Don Chea Date: Wed, 28 Jun 2023 09:11:14 -0400 Subject: [PATCH 3/3] Always pass headers as array to downloader, if present We still need to support it being named "header" in the Cask url stanza. --- Library/Homebrew/cask/url.rb | 4 +++- Library/Homebrew/download_strategy.rb | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/url.rb b/Library/Homebrew/cask/url.rb index 88f316bda1..dfd0ad23e5 100644 --- a/Library/Homebrew/cask/url.rb +++ b/Library/Homebrew/cask/url.rb @@ -57,6 +57,8 @@ module Cask @uri = URI(uri) + header = Array(header) unless header.nil? + specs = {} specs[:verified] = @verified = verified specs[:using] = @using = using @@ -67,7 +69,7 @@ module Cask specs[:trust_cert] = @trust_cert = trust_cert specs[:cookies] = @cookies = cookies specs[:referer] = @referer = referer - specs[:header] = @header = header + specs[:headers] = @header = header specs[:user_agent] = @user_agent = user_agent || :default specs[:data] = @data = data specs[:only_path] = @only_path = only_path diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 2b409eba30..78632ca56a 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -389,12 +389,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy # Merge `:header` with `:headers`. if (header = meta.delete(:header)) meta[:headers] ||= [] - - if header.is_a?(Array) - meta[:headers] += header - else - meta[:headers] << header - end + meta[:headers] << header end super