cache_rules 0.1.16 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/cache_rules.gemspec +1 -1
- data/lib/helpers.rb +5 -5
- data/test/test_validations.rb +7 -6
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/cache_rules.gemspec
CHANGED
data/lib/helpers.rb
CHANGED
@@ -68,7 +68,7 @@ module CacheRules
|
|
68
68
|
headers_304 = helper_headers_200_304.call(cached, normalized) if status == 200 || status == 304
|
69
69
|
headers_url = {'Location' => url} if status == 307
|
70
70
|
|
71
|
-
headers = [age, warning, x_cache,
|
71
|
+
headers = [headers_304, age, warning, x_cache, headers_url].compact.reduce &:merge
|
72
72
|
|
73
73
|
{:body => body, :code => status, :headers => headers}
|
74
74
|
end
|
@@ -249,7 +249,7 @@ module CacheRules
|
|
249
249
|
date_value = cached['Date']['timestamp'] # Required
|
250
250
|
request_time = cached['X-Cache-Req-Date']['timestamp'] # Required
|
251
251
|
response_time = cached['X-Cache-Res-Date']['timestamp'] # Required
|
252
|
-
age_value = cached['Age'].nil? ? 0 : cached['Age']
|
252
|
+
age_value = cached['Age'].nil? ? 0 : cached['Age'].to_i
|
253
253
|
|
254
254
|
apparent_age = helper_apparent_age response_time, date_value
|
255
255
|
corrected_age_value = helper_corrected_age_value response_time, request_time, age_value
|
@@ -285,12 +285,12 @@ module CacheRules
|
|
285
285
|
return (cached_headers['Expires']['timestamp'] - cached_headers['Date']['timestamp']) if cached_headers['Expires']
|
286
286
|
end
|
287
287
|
|
288
|
-
# Calculate Heuristic Freshness if there's
|
288
|
+
# Calculate Heuristic Freshness if there's no explicit expiration time
|
289
289
|
# source: https://tools.ietf.org/html/rfc7234#section-4.2.2
|
290
290
|
def helper_heuristic(now, cached, current_age)
|
291
|
-
# Use 10% only if
|
291
|
+
# Use 10% only if there's a Last-Modified header
|
292
292
|
# source: https://tools.ietf.org/html/rfc7234#section-4.2.2
|
293
|
-
if cached['
|
293
|
+
if cached['Last-Modified']
|
294
294
|
result = (now - cached['Last-Modified']['timestamp']) / 10
|
295
295
|
|
296
296
|
# Don't cache heuristic responses more than 24 hours old, and avoid sending a 113 Warning ;)
|
data/test/test_validations.rb
CHANGED
@@ -65,9 +65,10 @@ class TestValidations < MiniTest::Test
|
|
65
65
|
@headers_nothing = {
|
66
66
|
:request => {"If-None-Match" => ["\"myetag\""] },
|
67
67
|
:cached => {
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"X-Cache-
|
68
|
+
"Expires" => next_date,
|
69
|
+
"Date" => date,
|
70
|
+
"X-Cache-Req-Date" => date,
|
71
|
+
"X-Cache-Res-Date" => date,
|
71
72
|
"Cache-Control" => {
|
72
73
|
"must-revalidate" => {"token"=>nil, "quoted_string"=>nil}
|
73
74
|
}
|
@@ -121,9 +122,9 @@ class TestValidations < MiniTest::Test
|
|
121
122
|
stale = CacheRules.validate_expired? @headers
|
122
123
|
fresh = CacheRules.validate_expired? @headers_nothing
|
123
124
|
|
124
|
-
assert_equal
|
125
|
-
assert_equal
|
126
|
-
assert_equal
|
125
|
+
assert_equal 0, guard
|
126
|
+
assert_equal 1, stale
|
127
|
+
assert_equal 0, fresh
|
127
128
|
end
|
128
129
|
|
129
130
|
def test_only_if_cached
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_rules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fakeweb
|