Class: Protocol::HTTP::Header::ETags
- Defined in:
- lib/protocol/http/header/etags.rb
Overview
The ‘etags` header represents a list of entity tags (ETags) for resources.
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.
Constant Summary
Constants inherited from Split
Instance Method Summary collapse
-
#match?(etag) ⇒ Boolean
Checks if the specified ETag matches the ‘etags` header.
-
#strong_match?(etag) ⇒ Boolean
Checks for a strong match with the specified ETag, useful with the ‘if-match` header.
-
#weak_match?(etag) ⇒ Boolean
Checks for a weak match with the specified ETag, useful with the ‘if-none-match` header.
-
#wildcard? ⇒ Boolean
Checks if the ‘etags` header contains the wildcard (`*`) character.
Methods inherited from Split
#<<, coerce, #initialize, parse, #to_s, trailer?
Constructor Details
This class inherits a constructor from Protocol::HTTP::Header::Split
Instance Method Details
#match?(etag) ⇒ Boolean
Checks if the specified ETag matches 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.
31 32 33 |
# File 'lib/protocol/http/header/etags.rb', line 31 def match?(etag) wildcard? || self.include?(etag) end |
#strong_match?(etag) ⇒ Boolean
Checks for a strong match with the specified ETag, useful with the ‘if-match` header.
A strong match requires that the ETag in the header list matches the specified ETag and that neither is a weak validator.
41 42 43 |
# File 'lib/protocol/http/header/etags.rb', line 41 def strong_match?(etag) wildcard? || (!weak_tag?(etag) && self.include?(etag)) end |
#weak_match?(etag) ⇒ Boolean
Checks for a weak match with the specified ETag, useful with the ‘if-none-match` header.
A weak match allows for semantically equivalent content, including weak validators and their strong counterparts.
51 52 53 |
# File 'lib/protocol/http/header/etags.rb', line 51 def weak_match?(etag) wildcard? || self.include?(etag) || self.include?(opposite_tag(etag)) end |
#wildcard? ⇒ Boolean
Checks if the ‘etags` header contains the wildcard (`*`) character.
The wildcard character matches any resource version, regardless of its actual value.
21 22 23 |
# File 'lib/protocol/http/header/etags.rb', line 21 def wildcard? self.include?("*") end |