aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-02-18 16:32:05 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-02-18 16:32:05 +0000
commit109d4ac95443421da93bbad1d02e949429362221 (patch)
tree438211bf8c4cb207ae5751fcfa25c0da1f2f3d48
parentc9260c556ca5e238225de23bf2fd2cf21400f8aa (diff)
downloadrails-109d4ac95443421da93bbad1d02e949429362221.tar.gz
rails-109d4ac95443421da93bbad1d02e949429362221.tar.bz2
rails-109d4ac95443421da93bbad1d02e949429362221.zip
Allow people to set their own etags, if they want more control over the process (closes #7580) []
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6163 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rwxr-xr-xactionpack/lib/action_controller/base.rb4
-rw-r--r--actionpack/test/controller/render_test.rb7
2 files changed, 9 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 524d11de50..ecbe15bada 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -653,7 +653,7 @@ module ActionController #:nodoc:
#
# Rendering will automatically insert the etag header on 200 OK responses. The etag is calculated using MD5 of the
# response body. If a request comes in that has a matching etag, the response will be changed to a 304 Not Modified
- # and the response body will be set to an empty string.
+ # and the response body will be set to an empty string. No etag header will be inserted if it's already set.
#
# === Rendering a template
#
@@ -879,7 +879,7 @@ module ActionController #:nodoc:
if text.is_a?(String)
if response.headers['Status'][0..2] == '200' && !response.body.empty?
- response.headers['Etag'] = %("#{Digest::MD5.hexdigest(text)}")
+ response.headers['Etag'] ||= %("#{Digest::MD5.hexdigest(text)}")
if request.headers['HTTP_IF_NONE_MATCH'] == response.headers['Etag']
response.headers['Status'] = "304 Not Modified"
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index dd5255ce35..fb784d3e02 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -328,6 +328,13 @@ class RenderTest < Test::Unit::TestCase
assert_nil @response.headers['Etag']
end
+ def test_etag_should_not_be_changed_when_already_set
+ expected_etag = etag_for("hello somewhere else")
+ @response.headers["Etag"] = expected_etag
+ get :render_hello_world_from_variable
+ assert_equal expected_etag, @response.headers['Etag']
+ end
+
protected
def assert_deprecated_render(&block)
assert_deprecated(/render/, &block)