Module: Philiprehberger::Etag
- Defined in:
- lib/philiprehberger/etag.rb,
lib/philiprehberger/etag/parser.rb,
lib/philiprehberger/etag/matcher.rb,
lib/philiprehberger/etag/version.rb,
lib/philiprehberger/etag/generator.rb,
lib/philiprehberger/etag/middleware.rb,
lib/philiprehberger/etag/conditional.rb
Defined Under Namespace
Modules: Conditional, Generator, Matcher, Parser Classes: Error, Middleware
Constant Summary collapse
- VERSION =
'0.3.0'
Class Method Summary collapse
-
.equal?(a, b) ⇒ Boolean
Compare two ETag strings using weak comparison semantics (W/ prefix is ignored).
-
.for_file(path, algorithm: :sha256) ⇒ String
Generates a strong ETag for a file based on its mtime and size.
-
.generate(content, algorithm: :sha256) ⇒ String
Generates a strong ETag from content using the specified algorithm.
-
.match?(etag, if_none_match_header) ⇒ Boolean
Evaluates an ETag against an If-None-Match header using weak comparison.
-
.modified?(etag, request_headers) ⇒ Boolean
Checks if a resource has been modified based on request headers.
-
.modified_since?(last_modified, if_modified_since_header) ⇒ Boolean
Checks if a resource has been modified since the given If-Modified-Since header value.
-
.not_modified_since?(last_modified, if_modified_since_header) ⇒ Boolean
Checks if a resource has NOT been modified since the given If-Modified-Since header value.
-
.parse(header) ⇒ Hash+
Parses an ETag header value into a structured hash or array of hashes.
-
.strong_match?(etag, if_match_header) ⇒ Boolean
Evaluates an ETag against an If-Match header using strong comparison.
-
.weak(content) ⇒ String
Generates a weak ETag from content using MD5.
Class Method Details
.equal?(a, b) ⇒ Boolean
Compare two ETag strings using weak comparison semantics (W/ prefix is ignored).
93 94 95 96 97 |
# File 'lib/philiprehberger/etag.rb', line 93 def self.equal?(a, b) return false if a.nil? || b.nil? a.sub(%r{\AW/}, '') == b.sub(%r{\AW/}, '') end |
.for_file(path, algorithm: :sha256) ⇒ String
Generates a strong ETag for a file based on its mtime and size. Does not read file content.
67 68 69 |
# File 'lib/philiprehberger/etag.rb', line 67 def self.for_file(path, algorithm: :sha256) Generator.for_file(path, algorithm: algorithm) end |
.generate(content, algorithm: :sha256) ⇒ String
Generates a strong ETag from content using the specified algorithm.
20 21 22 |
# File 'lib/philiprehberger/etag.rb', line 20 def self.generate(content, algorithm: :sha256) Generator.strong(content, algorithm: algorithm) end |
.match?(etag, if_none_match_header) ⇒ Boolean
Evaluates an ETag against an If-None-Match header using weak comparison.
37 38 39 |
# File 'lib/philiprehberger/etag.rb', line 37 def self.match?(etag, if_none_match_header) Matcher.match?(etag, if_none_match_header) end |
.modified?(etag, request_headers) ⇒ Boolean
Checks if a resource has been modified based on request headers.
55 56 57 |
# File 'lib/philiprehberger/etag.rb', line 55 def self.modified?(etag, request_headers) Matcher.modified?(etag, request_headers) end |
.modified_since?(last_modified, if_modified_since_header) ⇒ Boolean
Checks if a resource has been modified since the given If-Modified-Since header value.
84 85 86 |
# File 'lib/philiprehberger/etag.rb', line 84 def self.modified_since?(last_modified, if_modified_since_header) Conditional.modified_since?(last_modified, if_modified_since_header) end |
.not_modified_since?(last_modified, if_modified_since_header) ⇒ Boolean
Checks if a resource has NOT been modified since the given If-Modified-Since header value.
104 105 106 |
# File 'lib/philiprehberger/etag.rb', line 104 def self.not_modified_since?(last_modified, if_modified_since_header) Conditional.not_modified_since?(last_modified, if_modified_since_header) end |
.parse(header) ⇒ Hash+
Parses an ETag header value into a structured hash or array of hashes.
75 76 77 |
# File 'lib/philiprehberger/etag.rb', line 75 def self.parse(header) Parser.parse(header) end |
.strong_match?(etag, if_match_header) ⇒ Boolean
Evaluates an ETag against an If-Match header using strong comparison.
46 47 48 |
# File 'lib/philiprehberger/etag.rb', line 46 def self.strong_match?(etag, if_match_header) Matcher.strong_match?(etag, if_match_header) end |