Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit ca14542

Browse files
committed
No max-stale = allow anything. Fixes issue #7
1 parent 7545c40 commit ca14542

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.1.15 (2015-04-29)
4+
5+
* No max-stale = allow anything. Fixes issue #7
6+
37
## 0.1.14 (2015-04-28)
48

59
* Ensure Cache-Control is verified

cache_rules.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require 'date'
66

77
Gem::Specification.new do |s|
88
s.name = 'cache_rules'
9-
s.version = '0.1.14'
9+
s.version = '0.1.15'
1010

1111
s.date = Date.today.to_s
1212

lib/helpers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ def helper_heuristic(now, cached, current_age)
303303

304304
# source: https://tools.ietf.org/html/rfc7234#section-5.2.1.2
305305
def helper_max_stale
306-
Proc.new {|request, freshness_lifetime, current_age|
306+
->(request, freshness_lifetime, current_age) {
307307
if request && request['max-stale']
308308
token = request['max-stale']['token']
309309
token ? (freshness_lifetime.to_i + token.to_i) > current_age : true
310+
else
311+
true
310312
end
311313
}
312314
end

test/test_cache_rules.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_validate_column3
7575
end
7676

7777
def test_validate_column4
78-
request = {"Host"=>"test.url", "Cache-Control"=>"max-stale=10000000"}
78+
request = {"Host"=>"test.url"}
7979
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "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}, "Last-Modified" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Last-Modified" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "ETag" => "\"validEtag\"", "Cache-Control"=>{"max-age"=>{"token"=>"100", "quoted_string" => nil}}}
8080

8181
result = CacheRules.validate('http://test.url/test1', request, cached)
@@ -87,7 +87,7 @@ def test_validate_column4
8787
end
8888

8989
def test_validate_column5
90-
request = {"Host"=>"test.url", "Cache-Control"=>"max-stale=10000000", "If-None-Match"=>"*"}
90+
request = {"Host"=>"test.url", "If-None-Match"=>"*"}
9191
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "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}, "Last-Modified" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Last-Modified" => {"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "ETag" => "\"validEtag\"", "Cache-Control"=>{"max-age"=>{"token"=>"100", "quoted_string" => nil}}}
9292

9393
result = CacheRules.validate('http://test.url/test1', request, cached)

test/test_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def test_max_stale
376376

377377
assert_kind_of TrueClass, stale
378378
assert_kind_of FalseClass, fresh
379-
assert_nil noop
379+
assert_kind_of TrueClass, noop
380380
assert_kind_of TrueClass, notoken
381381
end
382382

test/test_regressions.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@ def test_bugfix_5_age_header_string_integer
2626
assert_kind_of String, age_string['Age']
2727
assert_kind_of Integer, age_integer
2828
end
29+
30+
# https://github.com/aw/CacheRules/issues/7
31+
def test_bugfix_7_invalid_validation_of_max_stale
32+
request = {"Host"=>"test.url"}
33+
34+
no_max_stale = CacheRules.helper_max_stale.call request, 0, 0
35+
36+
assert_kind_of TrueClass, no_max_stale
37+
end
2938
end

0 commit comments

Comments
 (0)