Make Strategy#page_headers more general purpose

This commit is contained in:
Sam Ford 2020-12-19 00:46:18 -05:00
parent 1bd2be5e04
commit 7f40198506
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
2 changed files with 11 additions and 7 deletions

View File

@ -86,7 +86,7 @@ module Homebrew
return @headers[url] if @headers.key?(url)
headers = {}
headers = []
[:default, :browser].each do |user_agent|
stdout, _, status = curl_output(
@ -99,9 +99,9 @@ module Homebrew
while stdout.match?(/\AHTTP.*\r$/)
h, stdout = stdout.split("\r\n\r\n", 2)
headers = headers.merge(h.split("\r\n").drop(1)
.map { |header| header.split(/:\s*/, 2) }
.to_h.transform_keys(&:downcase))
headers << h.split("\r\n").drop(1)
.map { |header| header.split(/:\s*/, 2) }
.to_h.transform_keys(&:downcase)
end
return (@headers[url] = headers) if status.success?

View File

@ -36,12 +36,16 @@ module Homebrew
headers = Strategy.page_headers(url)
# Merge the headers from all responses into one hash
merged_headers = {}
headers.each { |resp_headers| merged_headers.merge!(resp_headers) }
if block
match = block.call(headers)
match = block.call(merged_headers)
else
match = nil
if (filename = headers["content-disposition"])
if (filename = merged_headers["content-disposition"])
if regex
match ||= location[regex, 1]
else
@ -50,7 +54,7 @@ module Homebrew
end
end
if (location = headers["location"])
if (location = merged_headers["location"])
if regex
match ||= location[regex, 1]
else