Skip fetching headers if URL has .xml extension.

This commit is contained in:
Markus Reiter 2020-12-14 02:35:26 +01:00 committed by Sam Ford
parent 8b7f38faf0
commit f76b5f105f
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE

View File

@ -21,9 +21,18 @@ module Homebrew
# Whether the strategy can be applied to the provided URL.
sig { params(url: String).returns(T::Boolean) }
def self.match?(url)
url.match?(%r{^https?://}) &&
["application/xml", "text/xml"].include?(Strategy.page_headers(url)["content-type"]) &&
Strategy.page_contents(url).include?("http://www.andymatuschak.org/xml-namespaces/sparkle")
return false unless url.match?(%r{^https?://})
xml = url.end_with?('.xml')
xml ||= begin
headers = Strategy.page_headers(url)
content_type = headers["content-type"]&.split(';', 2)&.first
["application/xml", "text/xml"].include?(content_type)
end
return false unless xml
contents = Strategy.page_contents(url)
contents.include?("http://www.andymatuschak.org/xml-namespaces/sparkle")
end
# Checks the content at the URL for new versions.