class Faraday::HttpCache::Request

Internal: A class to represent a request

Attributes

headers[R]
method[R]
url[R]

Public Class Methods

from_env(env) click to toggle source
# File lib/faraday/http_cache/request.rb, line 8
def from_env(env)
  hash = env.to_hash
  new(method: hash[:method], url: hash[:url], headers: hash[:request_headers].dup)
end
new(method:, url:, headers:) click to toggle source
# File lib/faraday/http_cache/request.rb, line 16
def initialize(method:, url:, headers:)
  @method = method
  @url = url
  @headers = headers
end

Public Instance Methods

cache_control() click to toggle source

Internal: Gets the ‘CacheControl’ object.

# File lib/faraday/http_cache/request.rb, line 37
def cache_control
  @cache_control ||= CacheControl.new(headers['Cache-Control'])
end
cacheable?() click to toggle source

Internal: Validates if the current request method is valid for caching.

Returns true if the method is ‘:get’ or ‘:head’.

# File lib/faraday/http_cache/request.rb, line 25
def cacheable?
  return false if method != :get && method != :head
  return false if cache_control.no_store?

  true
end
no_cache?() click to toggle source
# File lib/faraday/http_cache/request.rb, line 32
def no_cache?
  cache_control.no_cache?
end
serializable_hash() click to toggle source
# File lib/faraday/http_cache/request.rb, line 41
def serializable_hash
  {
    method: @method,
    url: @url.to_s,
    headers: @headers
  }
end