aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/response.rb6
-rw-r--r--actionpack/test/controller/render_test.rb9
-rw-r--r--actionpack/test/controller/send_file_test.rb1
4 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 352c4253f4..1584ae5835 100644
--- a/actionpack/CHANGELOG
+++ b/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]
diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb
index 559c38efd0..4c37f09215 100644
--- a/actionpack/lib/action_controller/response.rb
+++ b/actionpack/lib/action_controller/response.rb
@@ -115,7 +115,11 @@ module ActionController # :nodoc:
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)
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 87733c2d33..a6721fd903 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -208,6 +208,10 @@ class TestController < ActionController::Base
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 @@ class EtagRenderTest < ActionController::TestCase
@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
diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb
index c003abf094..ffbaa457f8 100644
--- a/actionpack/test/controller/send_file_test.rb
+++ b/actionpack/test/controller/send_file_test.rb
@@ -69,6 +69,7 @@ class SendFileTest < Test::Unit::TestCase
assert_equal @controller.file_path, response.headers['X-Sendfile']
assert response.body.blank?
+ assert !response.etag?
end
def test_data