Skip to content
Snippets Groups Projects
Unverified Commit 10b5548e authored by Markus Reiter's avatar Markus Reiter Committed by Sam Ford
Browse files

Fix `page_headers` method for multiple headers.

parent 7762a597
No related branches found
No related tags found
No related merge requests found
......@@ -83,11 +83,27 @@ module Homebrew
def self.page_headers(url)
@headers ||= {}
@headers[url] ||= curl_output("--head", "--location", url).stdout
.split("\r\n\r\n", 2).first
.split("\r\n").drop(1)
.map { |header| header.split(/:\s*/, 2) }
.to_h.transform_keys(&:downcase)
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)
headers = headers.merge(h.split("\r\n").drop(1)
.map { |header| header.split(/:\s*/, 2) }
.to_h.transform_keys(&:downcase))
end
@headers[url] = headers
end
def self.page_contents(url)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment