Class: Homebrew::Livecheck::Strategy::HeaderMatch Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
brew/Library/Homebrew/livecheck/strategy/header_match.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The HeaderMatch strategy follows all URL redirections and scans the resulting headers for matching text using the provided regex.

Constant Summary collapse

NICE_NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"Header match"
PRIORITY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

A priority of zero causes livecheck to skip the strategy. We only apply Homebrew::Livecheck::Strategy::HeaderMatch using strategy :header_match in a livecheck block, as we can’t automatically determine when this can be successfully applied to a URL.

0
URL_MATCH_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The Regexp used to determine if the strategy applies to the URL.

%r{^https?://}i.freeze

Class Method Summary collapse

Class Method Details

.find_versions(url, regex, &block) ⇒ Hash{Symbol => T.untyped}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks the final URL for new versions after following all redirections, using the provided regex for matching.

Parameters:

  • url (String)
  • regex (Regexp, nil)

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'brew/Library/Homebrew/livecheck/strategy/header_match.rb', line 39

def self.find_versions(url, regex, &block)
  match_data = { matches: {}, regex: regex, url: url }

  headers = Strategy.page_headers(url)

  # Merge the headers from all responses into one hash
  merged_headers = headers.reduce(&:merge)

  if block
    match = block.call(merged_headers, regex)
  else
    match = nil

    if (filename = merged_headers["content-disposition"])
      if regex
        match ||= filename[regex, 1]
      else
        v = Version.parse(filename, detected_from_url: true)
        match ||= v.to_s unless v.null?
      end
    end

    if (location = merged_headers["location"])
      if regex
        match ||= location[regex, 1]
      else
        v = Version.parse(location, detected_from_url: true)
        match ||= v.to_s unless v.null?
      end
    end
  end

  match_data[:matches][match] = Version.new(match) if match

  match_data
end

.match?(url) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Whether the strategy can be applied to the provided URL. The strategy will technically match any HTTP URL but is only usable with a livecheck block containing a regex or block.

Parameters:

Returns:

  • (Boolean)


32
33
34
# File 'brew/Library/Homebrew/livecheck/strategy/header_match.rb', line 32

def self.match?(url)
  URL_MATCH_REGEX.match?(url)
end