Class: Async::HTTP::Cache::Store::Vary
- Inherits:
-
Object
- Object
- Async::HTTP::Cache::Store::Vary
- Defined in:
- lib/async/http/cache/store/vary.rb
Instance Attribute Summary collapse
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(delegate, vary = {}) ⇒ Vary
constructor
A new instance of Vary.
- #insert(key, request, response) ⇒ Object
- #key_for(headers, vary) ⇒ Object
- #lookup(key, request) ⇒ Object
- #normalize(request) ⇒ Object
Constructor Details
#initialize(delegate, vary = {}) ⇒ Vary
Returns a new instance of Vary.
14 15 16 17 |
# File 'lib/async/http/cache/store/vary.rb', line 14 def initialize(delegate, vary = {}) @delegate = delegate @vary = vary end |
Instance Attribute Details
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
23 24 25 |
# File 'lib/async/http/cache/store/vary.rb', line 23 def delegate @delegate end |
Instance Method Details
#close ⇒ Object
19 20 21 |
# File 'lib/async/http/cache/store/vary.rb', line 19 def close @delegate.close end |
#insert(key, request, response) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/async/http/cache/store/vary.rb', line 48 def insert(key, request, response) if vary = response.headers[VARY]&.sort @vary[key] = vary key = key + key_for(request.headers, vary) end @delegate.insert(key, request, response) end |
#key_for(headers, vary) ⇒ Object
35 36 37 |
# File 'lib/async/http/cache/store/vary.rb', line 35 def key_for(headers, vary) vary.map{|key| headers[key]} end |
#lookup(key, request) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/async/http/cache/store/vary.rb', line 39 def lookup(key, request) if vary = @vary[key] # We should provide user-supported normalization here: key = key + key_for(request.headers, vary) end return @delegate.lookup(key, request) end |
#normalize(request) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/async/http/cache/store/vary.rb', line 25 def normalize(request) if accept_encoding = request.headers[ACCEPT_ENCODING] if accept_encoding.include?("gzip") request.headers.set(ACCEPT_ENCODING, "gzip") else request.headers.delete(ACCEPT_ENCODING) end end end |