Module: Philiprehberger::Etag::Conditional

Defined in:
lib/philiprehberger/etag/conditional.rb

Overview

Evaluates If-Modified-Since conditional requests based on timestamps.

Class Method Summary collapse

Class Method Details

.modified_since?(last_modified, if_modified_since_header) ⇒ Boolean

Checks if a resource has been modified since the given If-Modified-Since header value. Compares the resource’s last modified time against the header’s parsed date.

Parameters:

  • last_modified (Time)

    the last modification time of the resource

  • if_modified_since_header (String)

    the If-Modified-Since header value (RFC 2822)

Returns:

  • (Boolean)

    true if the resource has been modified since the header date



15
16
17
18
19
20
21
22
# File 'lib/philiprehberger/etag/conditional.rb', line 15

def self.modified_since?(last_modified, if_modified_since_header)
  return true if if_modified_since_header.nil? || if_modified_since_header.strip.empty?

  header_time = parse_time(if_modified_since_header)
  return true if header_time.nil?

  last_modified.to_i > header_time.to_i
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. Convenience inverse of modified_since?.

Parameters:

  • last_modified (Time)

    the last modification time of the resource

  • if_modified_since_header (String)

    the If-Modified-Since header value (RFC 2822)

Returns:

  • (Boolean)

    true if the resource has NOT been modified since the header date



30
31
32
# File 'lib/philiprehberger/etag/conditional.rb', line 30

def self.not_modified_since?(last_modified, if_modified_since_header)
  !modified_since?(last_modified, if_modified_since_header)
end