Skip to content

Commit

Permalink
Etagging ignores appended and block responses.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Feb 18, 2007
1 parent 392c7f7 commit 4fd84aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
20 changes: 11 additions & 9 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -7,7 +7,7 @@
require 'action_controller/status_codes' require 'action_controller/status_codes'
require 'drb' require 'drb'
require 'set' require 'set'
require 'md5' require 'digest/md5'


module ActionController #:nodoc: module ActionController #:nodoc:
class ActionControllerError < StandardError #:nodoc: class ActionControllerError < StandardError #:nodoc:
Expand Down Expand Up @@ -876,17 +876,19 @@ def render_text(text = nil, status = nil, append_response = false) #:nodoc:
response.body << text response.body << text
else else
response.body = text response.body = text
end


if response.headers['Status'] == "200 OK" && response.body.size > 0 if text.is_a?(String)
response.headers['Etag'] = "\"#{MD5.new(text).to_s}\"" if response.headers['Status'][0..2] == '200' && !response.body.empty?

response.headers['Etag'] = %("#{Digest::MD5.hexdigest(text)}")
if request.headers['HTTP_IF_NONE_MATCH'] == response.headers['Etag']
response.headers['Status'] = "304 Not Modified" if request.headers['HTTP_IF_NONE_MATCH'] == response.headers['Etag']
response.body = '' response.headers['Status'] = "304 Not Modified"
response.body = ''
end
end
end end
end end

response.body response.body
end end


Expand Down
10 changes: 5 additions & 5 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -311,13 +311,13 @@ def test_render_against_etag_request_should_200_when_no_match


def test_render_with_etag def test_render_with_etag
get :render_hello_world_from_variable get :render_hello_world_from_variable
expected_etag = "\"#{MD5.new("hello david").to_s}\"" expected_etag = etag_for('hello david')
assert_equal expected_etag, @response.headers['Etag'] assert_equal expected_etag, @response.headers['Etag']

@request.headers["HTTP_IF_NONE_MATCH"] = expected_etag @request.headers["HTTP_IF_NONE_MATCH"] = expected_etag
get :render_hello_world_from_variable get :render_hello_world_from_variable
assert_equal "304 Not Modified", @response.headers['Status'] assert_equal "304 Not Modified", @response.headers['Status']

@request.headers["HTTP_IF_NONE_MATCH"] = "\"diftag\"" @request.headers["HTTP_IF_NONE_MATCH"] = "\"diftag\""
get :render_hello_world_from_variable get :render_hello_world_from_variable
assert_equal "200 OK", @response.headers['Status'] assert_equal "200 OK", @response.headers['Status']
Expand All @@ -332,8 +332,8 @@ def render_with_404_shouldnt_have_etag
def assert_deprecated_render(&block) def assert_deprecated_render(&block)
assert_deprecated(/render/, &block) assert_deprecated(/render/, &block)
end end

def etag_for(text) def etag_for(text)
"\"#{MD5.new(text).to_s}\"" %("#{Digest::MD5.hexdigest(text)}")
end end
end end

0 comments on commit 4fd84aa

Please sign in to comment.