cache_rules 0.1.17 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/README.md +2 -1
- data/cache_rules.gemspec +1 -1
- data/lib/validations.rb +15 -3
- data/test/test_regressions.rb +23 -1
- data/test/test_validations.rb +1 -1
- metadata +2 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,7 @@ HTTP Caching request.
|
|
49
49
|
| :------------------------| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|
50
50
|
| **Are the headers cached?** | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
|
51
51
|
| **Must revalidate?** | - | - | - | - | 0 | 0 | 0 | 1 | - |
|
52
|
-
| **No-cache or max-age
|
52
|
+
| **No-cache or max-age reached?** | - | - | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
|
53
53
|
| **Do Etags/If-None-Match match?** | - | - | 0 | 1 | 0 | 1 | - | - | - |
|
54
54
|
| **Is the cached data expired?** | - | - | 0 | 0 | 1 | 1 | 1 | 1 | - |
|
55
55
|
| **Is there an if-only-cached header?** | 0 | 1 | - | - | - | - | - | - | - |
|
@@ -125,6 +125,7 @@ To run the tests, type:
|
|
125
125
|
|
126
126
|
## TODO
|
127
127
|
|
128
|
+
* Validation of `s-maxage` [response header](https://tools.ietf.org/html/rfc7234#section-5.2.2.9)
|
128
129
|
* Handling `Vary` header and different representations for the same resource
|
129
130
|
* Handling `206 (Partial)` and `Range` headers for resuming downloads
|
130
131
|
* Handling `Cache-Control: private` headers
|
data/cache_rules.gemspec
CHANGED
data/lib/validations.rb
CHANGED
@@ -47,7 +47,11 @@ module CacheRules
|
|
47
47
|
|
48
48
|
response_is_fresh = freshness_lifetime.to_i > current_age
|
49
49
|
|
50
|
-
|
50
|
+
return 1 if headers[:cached]['Cache-Control'] &&
|
51
|
+
headers[:cached]['Cache-Control']['max-age'] &&
|
52
|
+
current_age > headers[:cached]['Cache-Control']['max-age']['token'].to_i
|
53
|
+
|
54
|
+
to_bit { (response_is_fresh != true) }
|
51
55
|
end
|
52
56
|
|
53
57
|
def validate_only_if_cached?(headers)
|
@@ -85,8 +89,16 @@ module CacheRules
|
|
85
89
|
|
86
90
|
# Must revalidate if this request header exists
|
87
91
|
# source: https://tools.ietf.org/html/rfc7234#section-5.2.1.4
|
88
|
-
|
89
|
-
|
92
|
+
if request_headers['Cache-Control']
|
93
|
+
_, current_age = helper_freshness_lifetime.call cached_headers
|
94
|
+
|
95
|
+
# If max-age is 0 or if the current age is above the max-age and max-stale isn't set
|
96
|
+
# source: https://tools.ietf.org/html/rfc7234#section-5.2.1.1
|
97
|
+
return 1 if (( request = request_headers['Cache-Control'] )) &&
|
98
|
+
request['no-cache'] ||
|
99
|
+
(!request['max-stale'] && request['max-age'] &&
|
100
|
+
(request['max-age']['token'].to_s == "0" || current_age > request['max-age']['token'].to_i))
|
101
|
+
end
|
90
102
|
|
91
103
|
# source: https://tools.ietf.org/html/rfc7234#section-5.2.2.2
|
92
104
|
# source: https://tools.ietf.org/html/rfc7234#section-3.2
|
data/test/test_regressions.rb
CHANGED
@@ -8,9 +8,11 @@ class TestRegressions < MiniTest::Test
|
|
8
8
|
def setup
|
9
9
|
@cached_headers = {
|
10
10
|
:cached => {
|
11
|
+
"Age" => "99999",
|
11
12
|
"Date" => {"httpdate"=>"Thu, 01 Jan 2015 07:03:45 GMT", "timestamp"=>1420095825},
|
12
13
|
"Cache-Control" => {
|
13
|
-
"public" => {"token"=>nil, "quoted_string"=>nil}
|
14
|
+
"public" => {"token"=>nil, "quoted_string"=>nil},
|
15
|
+
"max-age" => {"token"=>"10", "quoted_string"=>nil}
|
14
16
|
},
|
15
17
|
"X-Cache-Req-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625},
|
16
18
|
"X-Cache-Res-Date" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}
|
@@ -44,4 +46,24 @@ class TestRegressions < MiniTest::Test
|
|
44
46
|
assert_equal isnil, []
|
45
47
|
assert_equal isempty, []
|
46
48
|
end
|
49
|
+
|
50
|
+
# https://github.com/aw/CacheRules/issues/10
|
51
|
+
def test_bugfix_10_request_header_max_age_is_checked
|
52
|
+
request_maxage = CacheRules.validate_no_cache?({
|
53
|
+
:cached => @cached_headers[:cached],
|
54
|
+
:request => {"Cache-Control" => {"max-age" => {"token"=>0, "quoted_string"=>nil} } }
|
55
|
+
})
|
56
|
+
current = CacheRules.validate_no_cache?({
|
57
|
+
:cached => @cached_headers[:cached],
|
58
|
+
:request => {"Cache-Control" => {"max-age" => {"token"=>1000, "quoted_string"=>nil} } }
|
59
|
+
})
|
60
|
+
cached_max_age = CacheRules.validate_expired?({
|
61
|
+
:cached => @cached_headers[:cached],
|
62
|
+
:request => {}
|
63
|
+
})
|
64
|
+
|
65
|
+
assert_equal 1, request_maxage
|
66
|
+
assert_equal 1, current
|
67
|
+
assert_equal 1, cached_max_age
|
68
|
+
end
|
47
69
|
end
|
data/test/test_validations.rb
CHANGED
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.18
|
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-
|
12
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fakeweb
|