From f76b5f105f69eea12913eeda228b74ba3e591560 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 14 Dec 2020 02:35:26 +0100 Subject: [PATCH] Skip fetching headers if URL has `.xml` extension. --- Library/Homebrew/livecheck/strategy/sparkle.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index fa80a7a5f8..1f1b8a8ade 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -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.