Class: Rage::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/request.rb

Instance Method Summary collapse

Instance Method Details

#fresh?(etag:, last_modified:) ⇒ Boolean

Check if the request is fresh.

Examples:

request.fresh?(etag: "123", last_modified: Time.utc(2023, 12, 15))
request.fresh?(last_modified: Time.utc(2023, 12, 15))
request.fresh?(etag: "123")

Parameters:

  • etag (String)

    The etag of the requested resource.

  • last_modified (Time)

    The last modified time of the requested resource.

Returns:

  • (Boolean)

    True if the request is fresh, false otherwise.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rage/request.rb', line 27

def fresh?(etag:, last_modified:)
  # Always render response when no freshness information
  # is provided in the request.
  return false unless if_none_match || if_not_modified_since

  etag_matches?(
    requested_etags: if_none_match, response_etag: etag
  ) && not_modified?(
    request_not_modified_since: if_not_modified_since,
    response_last_modified: last_modified
  )
end

#headersObject

Get the request headers.

Examples:

request.headers["Content-Type"] # => "application/json"
request.headers["Connection"] # => "keep-alive"


15
16
17
# File 'lib/rage/request.rb', line 15

def headers
  @headers ||= Headers.new(@env)
end