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(options) ⇒ Request
constructor
A new instance of Request.
- #no_cache? ⇒ Boolean
- #serializable_hash ⇒ Object
Constructor Details
#initialize(options) ⇒ Request
Returns a new instance of Request.
15 16 17 |
# File 'lib/faraday/http_cache/request.rb', line 15 def initialize() @method, @url, @headers = [:method], [:url], [:headers] end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
13 14 15 |
# File 'lib/faraday/http_cache/request.rb', line 13 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
13 14 15 |
# File 'lib/faraday/http_cache/request.rb', line 13 def method @method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
13 14 15 |
# File 'lib/faraday/http_cache/request.rb', line 13 def url @url end |
Class Method Details
.from_env(env) ⇒ Object
7 8 9 10 |
# File 'lib/faraday/http_cache/request.rb', line 7 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.
33 34 35 |
# File 'lib/faraday/http_cache/request.rb', line 33 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’.
22 23 24 25 26 |
# File 'lib/faraday/http_cache/request.rb', line 22 def cacheable? return false if method != :get && method != :head return false if cache_control.no_store? true end |
#no_cache? ⇒ Boolean
28 29 30 |
# File 'lib/faraday/http_cache/request.rb', line 28 def no_cache? cache_control.no_cache? end |
#serializable_hash ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/faraday/http_cache/request.rb', line 37 def serializable_hash { method: @method, url: @url, headers: @headers } end |