Skip to content

Commit

Permalink
Don't set blank Cache-Control header in Rack::ETag
Browse files Browse the repository at this point in the history
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
stephencelis committed Jul 17, 2012
1 parent e4172e7 commit cefc6de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/rack/etag.rb
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions test/spec_etag.rb
Expand Up @@ -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)
Expand Down

0 comments on commit cefc6de

Please sign in to comment.