response_bank 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d25739f9bd846e1cd3364a422cc90590b32fcb5f7e56cd307af0e83f0d5ddac
4
- data.tar.gz: 14c1a7f96abcc45025cee9f998342fb6185779774dc72986ebb1a5bbcb96c413
3
+ metadata.gz: a2fbaca21dd928ad2b387d10300acbbb61dedca00a8cdab23247484af8c749bf
4
+ data.tar.gz: a4f81948c53b5e574e5bd3cb3a3c9d621c387a3040706aa0ee873ffc5dab5362
5
5
  SHA512:
6
- metadata.gz: b6120bc7a707fa5ddd1cd3a143e40681e375864b075fe0e74b1128cc4ee460690400a70c47599772addba8d2bee56b02ce14a820c5e4af376f0eaa154f1fe88c
7
- data.tar.gz: 5ae1545f2c40d7abbf06b8ba43c8d353cb171fc97ce667fa280c5f991c37f7e514c7673898a99242e446f9975ef22f4cb91eaa053165664a9c309fa4d6b39197
6
+ metadata.gz: b3a0956f4ab5b627d4e80f4349c16cc830b49eecb602357b52aedc3e60703ddd2547bca663656d28b4525dfd9f47a4b67d226f9eaca4322ff9da1acfa1351c00
7
+ data.tar.gz: 602e5ed4aca5b96d30b61fed0d90c814689424b986374f9f6030ee4f03c6c41db6138cd7542be475bd86c3cb94fcd77453d52a6e7b58c5d954f50ca2a25ead3b
@@ -22,8 +22,7 @@ module ResponseBank
22
22
 
23
23
  if env['cacheable.cache']
24
24
  if [200, 404, 301, 304].include?(status)
25
- headers['ETag'] = env['cacheable.key']
26
-
25
+ headers['ETag'] = %{"#{env['cacheable.key']}"}
27
26
  end
28
27
 
29
28
  if [200, 404, 301].include?(status) && env['cacheable.miss']
@@ -145,11 +145,14 @@ module ResponseBank
145
145
  # regen
146
146
  @headers.merge!(headers)
147
147
 
148
- # if a cache key hit and client doesn't match encoding, return the raw body
149
- if !@env['HTTP_ACCEPT_ENCODING'].to_s.include?(@headers['Content-Encoding'])
150
- ResponseBank.log("uncompressing payload for client as client doesn't require encoding")
151
- body = ResponseBank.decompress(body, @headers['Content-Encoding'])
152
- @headers.delete('Content-Encoding')
148
+ if @headers['Content-Encoding']
149
+ if !@env['HTTP_ACCEPT_ENCODING'].to_s.include?(@headers['Content-Encoding'])
150
+ ResponseBank.log("uncompressing payload for client as client doesn't require encoding")
151
+ body = ResponseBank.decompress(body, @headers['Content-Encoding'])
152
+ @headers.delete('Content-Encoding')
153
+ end
154
+ else
155
+ ResponseBank.log("Cache hit, but missing content-encoding in the cache value headers, maybe because of 301 or 404 response or empty body string")
153
156
  end
154
157
 
155
158
  [status, @headers, [body]]
@@ -163,13 +166,19 @@ module ResponseBank
163
166
  # If-None-Match: "abc"
164
167
  # If-None-Match: W/"abc"
165
168
  # If-None-Match: "abc", "def"
166
- # If-None-Match: "*"
169
+ # If-None-Match: *
167
170
  return false unless entity_tag
168
171
  return false unless if_none_match
169
172
 
173
+ return true if if_none_match == "*"
174
+
170
175
  # strictly speaking an unquoted etag is not valid, yet common
171
176
  # to avoid unintended greedy matches in we check for naked entity then includes with quoted entity values
172
- if_none_match == "*" || if_none_match == entity_tag || if_none_match.include?(%{"#{entity_tag}"})
177
+ entity_tag = %{"#{entity_tag}"} unless entity_tag.starts_with?('"')
178
+
179
+ if_none_match = %{"#{if_none_match}"} unless if_none_match.starts_with?('"') || if_none_match.starts_with?('W/"')
180
+
181
+ if_none_match == entity_tag || if_none_match.include?(entity_tag)
173
182
  end
174
183
 
175
184
  def stale_while_revalidate?(timestamp, cache_age_tolerance)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ResponseBank
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.2"
4
4
  end
data/lib/response_bank.rb CHANGED
@@ -64,7 +64,7 @@ module ResponseBank
64
64
  key = %{#{key}:#{hash_value_str(data[:version])}} if data[:version]
65
65
 
66
66
  # add the encoding to only the cache key but don't expose this detail in the entity_tag
67
- key = %{#{key}:#{hash_value_str(data[:encoding])}} if data[:encoding] && data[:encoding] != "gzip"
67
+ key = %{#{key}:#{hash_value_str(data[:encoding])}} if data[:encoding]
68
68
 
69
69
  key
70
70
  when Array
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: response_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Lütke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-04-04 00:00:00.000000000 Z
12
+ date: 2023-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack