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

Commit

Permalink
Revert "Fix min-fresh cache-control header for stale responses. #14"
Browse files Browse the repository at this point in the history
This reverts commit 9bfba4f.
  • Loading branch information
aw committed Jul 14, 2018
1 parent b2001ae commit 609ed2e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
5 changes: 0 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Changelog

## 0.6.0 (2018-07-14)

* Fixes issue #14. Thanks @SleeplessByte
* Ensure min-fresh cache-control header is used correctly for stale responses

## 0.5.0 (2015-05-04)

* Add a check which verifies if a precondition exists before revalidating
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def helper_min_fresh
Proc.new {|request, freshness_lifetime, current_age|
if request && request['min-fresh']
token = request['min-fresh']['token']
freshness_lifetime.to_i >= (current_age - token.to_i)
freshness_lifetime.to_i >= (current_age + token.to_i)
end
}
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_cache_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_validate_column1

def test_validate_column2
request = {"Host"=>"test.url"}
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Cache-Control"=>{"s-maxage"=>{"token"=>"1000000000", "quoted_string"=>nil}}, "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}}
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Cache-Control"=>{"s-maxage"=>{"token"=>"100000000", "quoted_string"=>nil}}, "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}}

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

Expand All @@ -65,7 +65,7 @@ def test_validate_column2

def test_validate_column3
request = {"Host"=>"test.url", "If-None-Match" => "*"}
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Cache-Control"=>{"s-maxage"=>{"token"=>"1000000000", "quoted_string"=>nil}}, "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}, "ETag" => "\"validEtag\""}
cached = {"Date"=>{"httpdate"=>"Sat, 03 Jan 2015 07:03:45 GMT", "timestamp"=>1420268625}, "Cache-Control"=>{"s-maxage"=>{"token"=>"100000000", "quoted_string"=>nil}}, "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}, "ETag" => "\"validEtag\""}

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

Expand Down Expand Up @@ -195,7 +195,7 @@ def test_revalidate_response_column3
end

def test_revalidate_response_column4
request = {"Host"=>"test.url", "If-None-Match"=>["\"validEtag\""], "Cache-Control"=>{"max-stale"=>{"token"=>"1000000000", "quoted_string"=>nil}}}
request = {"Host"=>"test.url", "If-None-Match"=>["\"validEtag\""], "Cache-Control"=>{"max-stale"=>{"token"=>"100000000", "quoted_string"=>nil}}}
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}, "ETag" => "\"validEtag\""}

FakeWeb.register_uri(:head, "http://test.url/test1", :status => ["504", "Gateway Timeout"], :date => "Sat, 03 Jan 2015 07:15:45 GMT", :ETag => "\"validEtag\"")
Expand Down
2 changes: 1 addition & 1 deletion test/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def test_max_stale
end

def test_min_fresh
min = CacheRules.helper_min_fresh.call({'min-fresh'=>{'token'=>1000}}, 0, 2000)
min = CacheRules.helper_min_fresh.call({'min-fresh'=>{'token'=>1000}}, 0, 0)
fresh = CacheRules.helper_min_fresh.call({'min-fresh'=>{'token'=>"1000"}}, 2000, 0)
noop = CacheRules.helper_min_fresh.call @request_headers_nothing, 0, 0

Expand Down
8 changes: 4 additions & 4 deletions test/test_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def setup
"Cache-Control" => cache_control
},
:cached => {
"Date" => {"httpdate"=>"Sat, 14 Jul 2018 11:54:26 GMT", "timestamp"=>1531569266},
"Date" => {"httpdate"=>"Wed, 21 Feb 2018 04:13:57 GMT", "timestamp"=>1519186437},
"Cache-Control" => {
"public" => {"token"=>nil, "quoted_string"=>nil},
"max-stale" => {"token"=>"100", "quoted_string"=>nil}
},
"Last-Modified" => {"httpdate"=>"Sat, 14 Jul 2018 11:54:26 GMT", "timestamp"=>1531569266},
"X-Cache-Req-Date" => {"httpdate"=>"Sat, 14 Jul 2018 11:54:26 GMT", "timestamp"=>1531569266},
"X-Cache-Res-Date" => {"httpdate"=>"Sat, 14 Jul 2018 11:54:26 GMT", "timestamp"=>1531569266}
"Last-Modified" => {"httpdate"=>"Wed, 21 Feb 2018 04:13:57 GMT", "timestamp"=>1519186437},
"X-Cache-Req-Date" => {"httpdate"=>"Wed, 21 Feb 2018 04:13:57 GMT", "timestamp"=>1519186437},
"X-Cache-Res-Date" => {"httpdate"=>"Wed, 21 Feb 2018 04:13:57 GMT", "timestamp"=>1519186437}
}
}
@headers_noetag = {
Expand Down

0 comments on commit 609ed2e

Please sign in to comment.