File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,9 +70,13 @@ def proxy_revalidate?
7070
7171 # Internal: Gets the 'stale-while-revalidate' directive as an Integer.
7272 #
73- # Returns nil if the 'stale-while-revalidate' directive isn't present.
73+ # Returns nil if the 'stale-while-revalidate' directive isn't present, or
74+ # assigned as boolean.
7475 def stale_while_revalidate
75- @directives [ 'stale-while-revalidate' ] . to_i if @directives . key? ( 'stale-while-revalidate' )
76+ return unless @directives . key? ( 'stale-while-revalidate' )
77+ return if @directives [ 'stale-while-revalidate' ] == true
78+
79+ @directives [ 'stale-while-revalidate' ] . to_i
7680 end
7781
7882 # Internal: Gets the String representation for the cache directives.
Original file line number Diff line number Diff line change 116116 cache_control = Faraday ::HttpCache ::CacheControl . new ( 'public, max-age=60' )
117117 expect ( cache_control . stale_while_revalidate ) . to be_nil
118118 end
119+
120+ it 'responds to #stale_while_revalidate with 0 when directive is invalid true string value' do
121+ cache_control = Faraday ::HttpCache ::CacheControl . new ( 'public, max-age=60, stale-while-revalidate=true' )
122+ expect ( cache_control . stale_while_revalidate ) . to eq ( 0 )
123+ end
124+
125+ it 'responds to #stale_while_revalidate with nil when directive has no integer assignment' do
126+ cache_control = Faraday ::HttpCache ::CacheControl . new ( 'public, max-age=60, stale-while-revalidate' )
127+ expect ( cache_control . stale_while_revalidate ) . to be_nil
128+ end
119129end
You can’t perform that action at this time.
0 commit comments