Skip to content

Commit 8a91e26

Browse files
author
David Roy
committed
setup spec for new headers
1 parent b3ea1fd commit 8a91e26

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format documentation

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ require 'grape/cache_control'
1818
# Cache-Control:public,max-age=900
1919
cache_control :public, max_age: 900
2020

21+
# Cache-Control:public,max-age=900,stale-while-revalidate=1600
22+
cache_control :public, max_age: 900, stale_while_revalidate: 1600
23+
24+
# Cache-Control:public,max-age=900,stale-while-error=1600
25+
cache_control :public, max_age: 900, stale_while_error: 1600
26+
2127
# Cache-Control:public,no-store,max-age=900,s-maxage=86400
2228
cache_control :public, :no_store, max_age: 900, s_maxage:86400
2329

lib/grape/cache_control.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ module CacheControl
1010
EXPIRES = 'Expires'.freeze
1111
TRUE = 'true'.freeze
1212
SETTABLE_DIRECTIVES = [:max_age, :s_maxage].freeze
13-
TRUTHY_DIRECTIVES = [:public, :private, :no_cache, :no_store, :no_transform, :must_revalidate, :proxy_revalidate].freeze
13+
TRUTHY_DIRECTIVES = [:public, :private, :no_cache, :no_store, :no_transform,
14+
:must_revalidate, :proxy_revalidate, :stale_while_revalidate,
15+
:stale_while_error].freeze
1416
ALL_DIRECTIVES = (TRUTHY_DIRECTIVES | SETTABLE_DIRECTIVES).freeze
1517

1618
ALL_DIRECTIVES.each do |d|

spec/unit/grape/cache_control_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ def app
6666
expect(last_response.headers['Cache-Control'].split(', ')).to include('public', 'max-age=60')
6767
end
6868

69+
it 'supports stale-while-revalidate' do
70+
subject.get('/stale_blueberries') do
71+
cache_control :public, stale_while_revalidate: 120
72+
end
73+
74+
get 'stale_blueberries'
75+
expect(last_response.headers['Cache-Control'].split(', ')).to include('public', 'stale-while-revalidate=120')
76+
end
77+
78+
it 'supports stale-while-error' do
79+
subject.get('/error_blueberries') do
80+
cache_control :public, stale_while_error: 120
81+
end
82+
83+
get 'error_blueberries'
84+
expect(last_response.headers['Cache-Control'].split(', ')).to include('public', 'stale-while-error=120')
85+
end
6986
end
7087

7188
describe 'expires' do

0 commit comments

Comments
 (0)