cache_rules 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +7 -0
- data/cache_rules.gemspec +1 -1
- data/lib/helpers.rb +2 -2
- data/lib/validations.rb +11 -11
- data/test/test_helpers.rb +1 -1
- data/test/test_validations.rb +5 -5
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 0.3.0 (2015-05-03)
|
4
|
+
|
5
|
+
* Make cache rules consistent based RFC spec
|
6
|
+
* Add required 'cached' headers to tests
|
7
|
+
|
3
8
|
# 0.2.0 (2015-05-02)
|
4
9
|
|
10
|
+
* Version bump
|
11
|
+
|
5
12
|
# 0.1.20 (2015-05-01)
|
6
13
|
|
7
14
|
* Recently cached responses are cached correctly. Fixes issue #11
|
data/cache_rules.gemspec
CHANGED
data/lib/helpers.rb
CHANGED
@@ -293,9 +293,9 @@ module CacheRules
|
|
293
293
|
if cached['Last-Modified']
|
294
294
|
result = (now - cached['Last-Modified']['timestamp']) / 10
|
295
295
|
|
296
|
-
# Don't
|
296
|
+
# Don't return heuristic responses more than 24 hours old, and avoid sending a 113 Warning ;)
|
297
297
|
# source: https://tools.ietf.org/html/rfc7234#section-4.2.2
|
298
|
-
current_age > 86400 ? 0 :
|
298
|
+
current_age > 86400 ? 0 : result
|
299
299
|
else
|
300
300
|
0
|
301
301
|
end
|
data/lib/validations.rb
CHANGED
@@ -51,6 +51,7 @@ module CacheRules
|
|
51
51
|
headers[:cached]['Cache-Control']['max-age'] &&
|
52
52
|
current_age > headers[:cached]['Cache-Control']['max-age']['token'].to_i
|
53
53
|
|
54
|
+
|
54
55
|
to_bit { (response_is_fresh != true) }
|
55
56
|
end
|
56
57
|
|
@@ -82,23 +83,22 @@ module CacheRules
|
|
82
83
|
to_bit { (( cached = headers[:cached]['Cache-Control'] )) && ( cached['must-revalidate'] || cached['proxy-revalidate'] ) }
|
83
84
|
end
|
84
85
|
|
85
|
-
# Verify if we're explicitly told not to
|
86
|
+
# Verify if we're explicitly told not to serve a response without revalidation
|
86
87
|
def validate_no_cache?(headers)
|
87
88
|
request_headers, cached_headers = headers.values_at :request, :cached
|
88
89
|
return 1 if cached_headers.length == 0
|
89
90
|
|
90
91
|
# Must revalidate if this request header exists
|
91
92
|
# source: https://tools.ietf.org/html/rfc7234#section-5.2.1.4
|
92
|
-
if request_headers['Cache-Control']
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
93
|
+
return 1 if (request_headers['Cache-Control'] && request_headers['Cache-Control']['no-cache'])
|
94
|
+
|
95
|
+
_, current_age = helper_freshness_lifetime.call cached_headers
|
96
|
+
|
97
|
+
# If max-age is 0 or if the current age is above the max-age
|
98
|
+
# source: https://tools.ietf.org/html/rfc7234#section-5.2.1.1
|
99
|
+
return 1 if request_headers['Cache-Control'] &&
|
100
|
+
request_headers['Cache-Control']['max-age'] &&
|
101
|
+
(request_headers['Cache-Control']['max-age']['token'].to_s == "0" || current_age > request_headers['Cache-Control']['max-age']['token'].to_i)
|
102
102
|
|
103
103
|
# source: https://tools.ietf.org/html/rfc7234#section-5.2.2.2
|
104
104
|
# source: https://tools.ietf.org/html/rfc7234#section-3.2
|
data/test/test_helpers.rb
CHANGED
@@ -362,7 +362,7 @@ class TestHelpers < MiniTest::Test
|
|
362
362
|
too_old = CacheRules.helper_heuristic now, @cached_headers, 86401
|
363
363
|
noop = CacheRules.helper_heuristic(now, {}, 42)
|
364
364
|
|
365
|
-
assert_equal last_modified,
|
365
|
+
assert_equal last_modified, 16560
|
366
366
|
assert_equal not_public, 0
|
367
367
|
assert_equal too_old, 0
|
368
368
|
assert_equal noop, 0
|
data/test/test_validations.rb
CHANGED
@@ -168,23 +168,23 @@ class TestValidations < MiniTest::Test
|
|
168
168
|
}
|
169
169
|
headers2 = {
|
170
170
|
:request => {},
|
171
|
-
:cached => {'Cache-Control' => {'no-cache'=>{'quoted_string'=>"Cookie"}}}
|
171
|
+
:cached => {'Cache-Control' => {'no-cache'=>{'quoted_string'=>"Cookie"}}, "Date" => {"httpdate" => "Thu, 01 Jan 2015 07:03:45 GMT", "timestamp"=>1420095825}, "X-Cache-Req-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "X-Cache-Res-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}}
|
172
172
|
}
|
173
173
|
headers2_nil = {
|
174
174
|
:request => {},
|
175
|
-
:cached => {'Cache-Control' => {'no-cache'=>{'quoted_string'=>nil}}}
|
175
|
+
:cached => {'Cache-Control' => {'no-cache'=>{'quoted_string'=>nil}}, "Date" => {"httpdate" => "Thu, 01 Jan 2015 07:03:45 GMT", "timestamp"=>1420095825}, "X-Cache-Req-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "X-Cache-Res-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}}
|
176
176
|
}
|
177
177
|
headers3 = {
|
178
178
|
:request => {},
|
179
|
-
:cached => {'Cache-Control' => {'s-maxage'=>{'token'=>"0"}}}
|
179
|
+
:cached => {'Cache-Control' => {'s-maxage'=>{'token'=>"0"}}, "Date" => {"httpdate" => "Thu, 01 Jan 2015 07:03:45 GMT", "timestamp"=>1420095825}, "X-Cache-Req-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "X-Cache-Res-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}}
|
180
180
|
}
|
181
181
|
headers4 = {
|
182
182
|
:request => {},
|
183
|
-
:cached => {'Cache-Control' => {'max-age'=>{'token'=>0}}}
|
183
|
+
:cached => {'Cache-Control' => {'max-age'=>{'token'=>0}}, "Date" => {"httpdate" => "Thu, 01 Jan 2015 07:03:45 GMT", "timestamp"=>1420095825}, "X-Cache-Req-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "X-Cache-Res-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}}
|
184
184
|
}
|
185
185
|
headers5 = {
|
186
186
|
:request => {'Pragma' => {'no-cache'=>{'token'=>nil}}},
|
187
|
-
:cached => {'Cache-Control' => {}}
|
187
|
+
:cached => {'Cache-Control' => {}, "Date" => {"httpdate" => "Thu, 01 Jan 2015 07:03:45 GMT", "timestamp"=>1420095825}, "X-Cache-Req-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "X-Cache-Res-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}}
|
188
188
|
}
|
189
189
|
|
190
190
|
guard = CacheRules.validate_no_cache? @no_headers
|
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.
|
4
|
+
version: 0.3.0
|
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-05-
|
12
|
+
date: 2015-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fakeweb
|