Add page_headers and page_contents helpers.
This commit is contained in:
parent
24046c3182
commit
f5d311490c
@ -80,6 +80,20 @@ module Homebrew
|
||||
(strategy.const_defined?(:PRIORITY) ? -strategy::PRIORITY : -DEFAULT_PRIORITY)
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def self.page_contents(url)
|
||||
@page_contents ||= {}
|
||||
@page_contents[url] ||= URI.parse(url).open.read
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,8 +30,8 @@ module Homebrew
|
||||
URL_MATCH_REGEX = %r{^https?://}i.freeze
|
||||
|
||||
# Whether the strategy can be applied to the provided URL.
|
||||
# PageMatch will technically match any HTTP URL but it's only usable
|
||||
# when the formula has a `livecheck` block containing a regex.
|
||||
# PageMatch will technically match any HTTP URL but is only
|
||||
# usable with a `livecheck` block containing a regex.
|
||||
#
|
||||
# @param url [String] the URL to match against
|
||||
# @return [Boolean]
|
||||
@ -47,9 +47,8 @@ module Homebrew
|
||||
# content
|
||||
# @return [Array]
|
||||
def self.page_matches(url, regex)
|
||||
page = URI.parse(url).open.read
|
||||
matches = page.scan(regex)
|
||||
matches.map(&:first).uniq
|
||||
page = Strategy.page_contents(url)
|
||||
page.scan(regex).map(&:first).uniq
|
||||
end
|
||||
|
||||
# Checks the content at the URL for new versions, using the provided
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user