Skip to content

Commit

Permalink
Merge pull request #171 from ykitamura-mdsol/fix/reset_cache_control_…
Browse files Browse the repository at this point in the history
…on_dup

Reset @cache_control in Response when duplicating its instance
  • Loading branch information
grosser authored Oct 16, 2020
2 parents 97819fb + 0ed321b commit 5260052
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/cache/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def initialize(status, headers, body)
def initialize_copy(other)
super
@headers = other.headers.dup
@cache_control = nil
end

# Return the status, headers, and body in a three-tuple.
Expand Down
23 changes: 23 additions & 0 deletions test/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,29 @@
cache.trace.must_include :pass
end

it 'does not cache when Cache-Control response header changed to private (reset @cache_control on dup)' do
count = 0
respond_with do |req,res|
count+= 1
res['Cache-Control'] = (count == 1) ? 'public' : 'private, no-store'
res['ETag'] = count.to_s
res.status = (count == 1) ? 200 : 304
end

get '/'
assert app.called?
assert response.ok?
cache.trace.must_include :miss
cache.trace.must_include :store

get '/'
assert app.called?
assert response.ok?
cache.trace.must_include :stale
cache.trace.must_include :valid
cache.trace.wont_include :store
end

it 'logs to rack.logger if available' do
logger = Class.new do
attr_reader :logged_level
Expand Down

0 comments on commit 5260052

Please sign in to comment.