diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-21 16:58:12 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-21 16:58:12 +0200 |
commit | 18542c9e00209679bdaacf64075819fb887ec856 (patch) | |
tree | 70fc26b9f2184547274908d386fca77326911393 /actionpack/lib | |
parent | a5cdb7a813515fa0cbee23101d2f911b4017ed90 (diff) | |
download | rails-18542c9e00209679bdaacf64075819fb887ec856.tar.gz rails-18542c9e00209679bdaacf64075819fb887ec856.tar.bz2 rails-18542c9e00209679bdaacf64075819fb887ec856.zip |
Dont try to auto-set the etag based on the body if any freshness headers have already been set [DHH/José Valim]
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/response.rb | 33 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_process.rb | 6 |
2 files changed, 27 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb index b440065482..559c38efd0 100644 --- a/actionpack/lib/action_controller/response.rb +++ b/actionpack/lib/action_controller/response.rb @@ -106,8 +106,14 @@ module ActionController # :nodoc: headers['Last-Modified'] = utc_time.httpdate end - def etag; headers['ETag'] end - def etag?; headers.include?('ETag') end + def etag + headers['ETag'] + end + + def etag? + headers.include?('ETag') + end + def etag=(etag) headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(etag))}") end @@ -135,16 +141,19 @@ module ActionController # :nodoc: end private - def handle_conditional_get! - if nonempty_ok_response? - self.etag ||= body - if request && request.etag_matches?(etag) - self.status = '304 Not Modified' - self.body = '' - end - end - - set_conditional_cache_control! if etag? || last_modified? + def handle_conditional_get! + if etag? || last_modified? + set_conditional_cache_control! + elsif nonempty_ok_response? + self.etag = body + + if request && request.etag_matches?(etag) + self.status = '304 Not Modified' + self.body = '' + end + + set_conditional_cache_control! + end end def nonempty_ok_response? diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index cde1f2052b..f84c48f102 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -284,6 +284,11 @@ module ActionController #:nodoc: # See AbstractResponse for more information on controller response objects. class TestResponse < AbstractResponse include TestResponseBehavior + + def recycle! + headers.delete('ETag') + headers.delete('Last-Modified') + end end class TestSession #:nodoc: @@ -386,6 +391,7 @@ module ActionController #:nodoc: end @request.recycle! + @response.recycle! @html_document = nil @request.env['REQUEST_METHOD'] ||= "GET" |