class Protocol::HTTP::Header::ETags
The ‘etags` header is used for conditional requests to compare the current version of a resource with previously stored versions. It supports both strong and weak validators, as well as the wildcard character (`*`) to indicate a match for any resource.
The `etags` header represents a list of entity tags (ETags) for resources.
def match?(etag)
@parameter etag [String] the ETag to compare against the `etags` header.
This method returns `true` if the wildcard is present or if the exact ETag is found in the list. Note that this implementation is not strictly compliant with the RFC-specified format.
Checks if the specified ETag matches the `etags` header.
def match?(etag) wildcard? || self.include?(etag) end
def opposite_tag(etag)
@parameter etag [String] the ETag to convert.
Converts a weak tag to its strong counterpart or vice versa.
def opposite_tag(etag) weak_tag?(etag) ? etag[2..-1] : "W/#{etag}" end
def strong_match?(etag)
@parameter etag [String] the ETag to compare against the `etags` header.
A strong match requires that the ETag in the header list matches the specified ETag and that neither is a weak validator.
Checks for a strong match with the specified ETag, useful with the `if-match` header.
def strong_match?(etag) wildcard? || (!weak_tag?(etag) && self.include?(etag)) end
def weak_match?(etag)
@parameter etag [String] the ETag to compare against the `etags` header.
A weak match allows for semantically equivalent content, including weak validators and their strong counterparts.
Checks for a weak match with the specified ETag, useful with the `if-none-match` header.
def weak_match?(etag) wildcard? || self.include?(etag) || self.include?(opposite_tag(etag)) end
def weak_tag?(tag)
@parameter tag [String] the ETag to check.
Checks if the given ETag is a weak validator.
def weak_tag?(tag) tag&.start_with? "W/" end
def wildcard?
The wildcard character matches any resource version, regardless of its actual value.
Checks if the `etags` header contains the wildcard (`*`) character.
def wildcard? self.include?("*") end