Skip to content

Commit 6379364

Browse files
committed
Fixed the case-insensitive nature of ignored response headers
1 parent 12ae92d commit 6379364

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rack/cache/context.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def store(response)
272272

273273
# Remove all ignored response headers before writing to the cache.
274274
def strip_ignore_headers(response)
275-
record :ignore if response.headers.reject! { |name, value| ignore_headers.include? name }
275+
stripped_values = ignore_headers.map { |name| response.headers.delete(name) }
276+
record :ignore if stripped_values.any?
276277
end
277278

278279
def log_error(exception)

test/context_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@
9797
response.headers['Set-Cookie'].should.be.nil
9898
end
9999

100+
it 'does remove all configured ignore_headers from a cacheable response' do
101+
respond_with 200, 'Cache-Control' => 'public', 'ETag' => '"FOO"', 'SET-COOKIE' => 'TestCookie=OK', 'X-Strip-Me' => 'Secret'
102+
get '/', 'rack-cache.ignore_headers' => ['set-cookie', 'x-strip-me']
103+
104+
app.should.be.called
105+
response.should.be.ok
106+
cache.trace.should.include :store
107+
cache.trace.should.include :ignore
108+
response.headers['Set-Cookie'].should.be.nil
109+
response.headers['x-strip-me'].should.be.nil
110+
end
111+
100112
it 'does not remove Set-Cookie response header from a private response' do
101113
respond_with 200, 'Cache-Control' => 'private', 'Set-Cookie' => 'TestCookie=OK'
102114
get '/'

0 commit comments

Comments
 (0)