Allow extracting file name in FollowRedirection strategy.
This commit is contained in:
parent
b3c46ba2b9
commit
df70296403
@ -30,15 +30,37 @@ module Homebrew
|
|||||||
# Checks the final URL for new versions after following all redirections,
|
# Checks the final URL for new versions after following all redirections,
|
||||||
# using the provided regex for matching.
|
# using the provided regex for matching.
|
||||||
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
|
sig { params(url: String, regex: T.nilable(Regexp)).returns(T::Hash[Symbol, T.untyped]) }
|
||||||
def self.find_versions(url, regex)
|
def self.find_versions(url, regex, &block)
|
||||||
raise ArgumentError, "A regular expression is required for the #{NICE_NAME} strategy." if regex.nil?
|
|
||||||
|
|
||||||
match_data = { matches: {}, regex: regex, url: url }
|
match_data = { matches: {}, regex: regex, url: url }
|
||||||
|
|
||||||
if (location = Strategy.page_headers(url)["location"]) && (match = location[regex, 1])
|
data = { headers: Strategy.page_headers(url) }
|
||||||
match_data[:matches][match] = Version.new(match)
|
|
||||||
|
if (filename = data[:headers]["content-disposition"])
|
||||||
|
if regex
|
||||||
|
data[:version] ||= location[regex, 1]
|
||||||
|
else
|
||||||
|
v = Version.parse(filename, detected_from_url: true)
|
||||||
|
data[:version] ||= v.to_s unless v.null?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (location = data[:headers]["location"])
|
||||||
|
if regex
|
||||||
|
data[:version] ||= location[regex, 1]
|
||||||
|
else
|
||||||
|
v = Version.parse(location, detected_from_url: true)
|
||||||
|
data[:version] ||= v.to_s unless v.null?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
version = if block
|
||||||
|
block.call(data)
|
||||||
|
else
|
||||||
|
data[:version]
|
||||||
|
end
|
||||||
|
|
||||||
|
match_data[:matches][version] = Version.new(version) if version
|
||||||
|
|
||||||
match_data
|
match_data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user