public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Do not output an ETag header if response body is blank or when sending files 
with send_file(... :xsendfile => true) [#1578 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Hongli Lai (Phusion (author)
Mon Dec 15 12:36:33 -0800 2008
dhh (committer)
Tue Dec 16 03:30:28 -0800 2008
commit  9e2b4a10f7f091868b3c3701efb4c04048455706
tree    b7bfb7a80b78a22e5ab562a7d26c3d01abc7631d
parent  7c090509994faa19fcbd534aa78324b70b659627
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.3.0 [Edge]*
0
 
0
+* Fixed that send_file shouldn't set an etag #1578 [Hongli Lai]
0
+
0
 * Allow users to opt out of the spoofing checks in Request#remote_ip.  Useful for sites whose traffic regularly triggers false positives. [Darren Boyd]
0
 
0
 * Deprecated formatted_polymorphic_url.  [Jeremy Kemper]
...
115
116
117
118
 
 
 
 
 
119
120
121
...
115
116
117
 
118
119
120
121
122
123
124
125
0
@@ -115,7 +115,11 @@ module ActionController # :nodoc:
0
     end
0
     
0
     def etag=(etag)
0
-      headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(etag))}")
0
+      if etag.blank?
0
+        headers.delete('ETag')
0
+      else
0
+        headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(etag))}")
0
+      end
0
     end
0
 
0
     def redirect(url, status)
...
208
209
210
 
 
 
 
211
212
213
...
1380
1381
1382
 
 
 
 
 
1383
1384
1385
...
208
209
210
211
212
213
214
215
216
217
...
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
0
@@ -208,6 +208,10 @@ class TestController < ActionController::Base
0
   def greeting
0
     # let's just rely on the template
0
   end
0
+  
0
+  def blank_response
0
+    render :text => ' '
0
+  end
0
 
0
   def layout_test
0
     render :action => "hello_world"
0
@@ -1380,6 +1384,11 @@ class EtagRenderTest < ActionController::TestCase
0
     @request.host = "www.nextangle.com"
0
     @expected_bang_etag = etag_for(expand_key([:foo, 123]))
0
   end
0
+  
0
+  def test_render_blank_body_shouldnt_set_etag
0
+    get :blank_response
0
+    assert !@response.etag?
0
+  end
0
 
0
   def test_render_200_should_set_etag
0
     get :render_hello_world_from_variable
...
69
70
71
 
72
73
74
...
69
70
71
72
73
74
75
0
@@ -69,6 +69,7 @@ class SendFileTest < Test::Unit::TestCase
0
 
0
     assert_equal @controller.file_path, response.headers['X-Sendfile']
0
     assert response.body.blank?
0
+    assert !response.etag?
0
   end
0
 
0
   def test_data

Comments