Class: Faraday::HttpCache::Request
- Inherits:
-
Object
- Object
- Faraday::HttpCache::Request
- Defined in:
- lib/faraday/http_cache/request.rb
Overview
Internal: A class to represent a request
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#cache_control ⇒ Object
Internal: Gets the ‘CacheControl’ object.
-
#cacheable? ⇒ Boolean
Internal: Validates if the current request method is valid for caching.
-
#initialize(method:, url:, headers:) ⇒ Request
constructor
A new instance of Request.
- #no_cache? ⇒ Boolean
- #serializable_hash ⇒ Object
Constructor Details
#initialize(method:, url:, headers:) ⇒ Request
Returns a new instance of Request.
16 17 18 19 20 |
# File 'lib/faraday/http_cache/request.rb', line 16 def initialize(method:, url:, headers:) @method = method @url = url @headers = headers end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
14 15 16 |
# File 'lib/faraday/http_cache/request.rb', line 14 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
14 15 16 |
# File 'lib/faraday/http_cache/request.rb', line 14 def method @method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/faraday/http_cache/request.rb', line 14 def url @url end |
Class Method Details
.from_env(env) ⇒ Object
8 9 10 11 |
# 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 |
Instance Method Details
#cache_control ⇒ Object
Internal: Gets the ‘CacheControl’ object.
37 38 39 |
# File 'lib/faraday/http_cache/request.rb', line 37 def cache_control @cache_control ||= CacheControl.new(headers['Cache-Control']) end |
#cacheable? ⇒ Boolean
Internal: Validates if the current request method is valid for caching.
Returns true if the method is ‘:get’ or ‘:head’.
25 26 27 28 29 30 |
# 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? ⇒ Boolean
32 33 34 |
# File 'lib/faraday/http_cache/request.rb', line 32 def no_cache? cache_control.no_cache? end |
#serializable_hash ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/faraday/http_cache/request.rb', line 41 def serializable_hash { method: @method, url: @url.to_s, headers: @headers } end |