Skip to content
Browse files

Do not output an ETag header if response body is blank or when sendin…

…g files with send_file(... :xsendfile => true) [#1578 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
1 parent 7c09050 commit 9e2b4a10f7f091868b3c3701efb4c04048455706 @FooBarWidget FooBarWidget committed with dhh Dec 15, 2008
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*2.3.0 [Edge]*
+* Fixed that send_file shouldn't set an etag #1578 [Hongli Lai]
+
* Allow users to opt out of the spoofing checks in Request#remote_ip. Useful for sites whose traffic regularly triggers false positives. [Darren Boyd]
* Deprecated formatted_polymorphic_url. [Jeremy Kemper]
View
6 actionpack/lib/action_controller/response.rb
@@ -115,7 +115,11 @@ def etag?
end
def etag=(etag)
- headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(etag))}")
+ if etag.blank?
+ headers.delete('ETag')
+ else
+ headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(etag))}")
+ end
end
def redirect(url, status)
View
9 actionpack/test/controller/render_test.rb
@@ -208,6 +208,10 @@ def heading
def greeting
# let's just rely on the template
end
+
+ def blank_response
+ render :text => ' '
+ end
def layout_test
render :action => "hello_world"
@@ -1380,6 +1384,11 @@ def setup
@request.host = "www.nextangle.com"
@expected_bang_etag = etag_for(expand_key([:foo, 123]))
end
+
+ def test_render_blank_body_shouldnt_set_etag
+ get :blank_response
+ assert !@response.etag?
+ end
def test_render_200_should_set_etag
get :render_hello_world_from_variable
View
1 actionpack/test/controller/send_file_test.rb
@@ -69,6 +69,7 @@ def test_x_sendfile_header
assert_equal @controller.file_path, response.headers['X-Sendfile']
assert response.body.blank?
+ assert !response.etag?
end
def test_data

0 comments on commit 9e2b4a1

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