cache_rules 0.1.16 → 0.1.17

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.17 (2015-04-30)
4
+
5
+ * Return the proper 'Age' header and ignore the 'public' control directive
6
+
3
7
  ## 0.1.16 (2015-04-29)
4
8
 
5
9
  * Errors caused by empty HTTP headers. Fixes issue #8
data/cache_rules.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'date'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'cache_rules'
9
- s.version = '0.1.16'
9
+ s.version = '0.1.17'
10
10
 
11
11
  s.date = Date.today.to_s
12
12
 
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, headers_304, headers_url].compact.reduce &:merge
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']['timestamp'].to_i
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 not explicit expiration time
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 the response is public and there's a Last-Modified header
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['Cache-Control'] && cached['Cache-Control']['public'] && cached['Last-Modified']
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 ;)
@@ -65,9 +65,10 @@ class TestValidations < MiniTest::Test
65
65
  @headers_nothing = {
66
66
  :request => {"If-None-Match" => ["\"myetag\""] },
67
67
  :cached => {
68
- "Date" => next_date,
69
- "X-Cache-Req-Date" => next_date,
70
- "X-Cache-Res-Date" => next_date,
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 guard, 0
125
- assert_equal stale, 1
126
- assert_equal fresh, 0
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.16
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-29 00:00:00.000000000 Z
12
+ date: 2015-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fakeweb