Skip to content
Browse files

Don't set blank Cache-Control header in Rack::ETag

A Cache-Control header with an empty string is meaningless (confusing,
even, to those inspecting response headers) and slightly wasteful.

Signed-off-by: Stephen Celis <stephen@stephencelis.com>
  • Loading branch information...
1 parent e4172e7 commit cefc6de66be545f681370eb39470db6ddf8d6582 @stephencelis stephencelis committed Jul 17, 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 cefc6de

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