Skip to content
Browse files

Merge pull request #410 from stephencelis/blank-rack-etag-cache-control

Don't set blank Cache-Control header in Rack::ETag
  • Loading branch information...
2 parents 03b1d6f + cefc6de commit 5a4c6913a596cd2fb6c6f98e7cfde158c9de0ef1 @raggi raggi committed Aug 26, 2012
Showing with 11 additions and 2 deletions.
  1. +5 −2 lib/rack/etag.rb
  2. +6 −0 test/spec_etag.rb
View
7 lib/rack/etag.rb
@@ -28,8 +28,11 @@ def call(env)
end
unless headers['Cache-Control']
- headers['Cache-Control'] =
- (digest ? @cache_control : @no_cache_control) || ""
+ if digest
+ headers['Cache-Control'] = @cache_control if @cache_control
+ else
+ headers['Cache-Control'] = @no_cache_control if @no_cache_control
+ end
end
[status, headers, body]
View
6 test/spec_etag.rb
@@ -54,6 +54,12 @@ def res.to_path ; "/tmp/hello.txt" ; end
response[1]['Cache-Control'].should.equal 'public'
end
+ should "not set Cache-Control if directive isn't present" do
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
+ response = etag(app, nil, nil).call(request)
+ response[1]['Cache-Control'].should.equal nil
+ end
+
should "not change ETag if it is already set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'ETag' => '"abc"'}, ["Hello, World!"]] }
response = etag(app).call(request)

0 comments on commit 5a4c691

Please sign in to comment.
Something went wrong with that request. Please try again.