Try getting headers with both user agents.

This commit is contained in:
Markus Reiter 2020-12-14 02:10:38 +01:00 committed by Sam Ford
parent 0fe3bf7c7f
commit b9741dd1e6
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE

View File

@ -90,24 +90,28 @@ module Homebrew
return @headers[url] if @headers.key?(url)
stdout, _, status = curl_output(
"--head", "--request", "GET", "--silent", "--location",
"--connect-timeout", 5, "--retry-max-time", 15, "--max-time", 10,
url
)
return {} unless status.success?
headers = {}
while stdout.match?(/\AHTTP.*\r$/)
h, stdout = stdout.split("\r\n\r\n", 2)
[:default, :browser].each do |user_agent|
stdout, _, status = curl_output(
"--fail", "--head", "--request", "GET", "--silent", "--location",
"--connect-timeout", 5, "--retry-max-time", 15, "--max-time", 10,
url,
user_agent: user_agent
)
headers = headers.merge(h.split("\r\n").drop(1)
.map { |header| header.split(/:\s*/, 2) }
.to_h.transform_keys(&:downcase))
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))
end
return headers if status.success?
end
@headers[url] = headers
headers
end
def self.page_contents(url)