mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Etagging ignores appended and block responses.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -7,7 +7,7 @@ require 'action_controller/url_rewriter'
|
||||
require 'action_controller/status_codes'
|
||||
require 'drb'
|
||||
require 'set'
|
||||
require 'md5'
|
||||
require 'digest/md5'
|
||||
|
||||
module ActionController #:nodoc:
|
||||
class ActionControllerError < StandardError #:nodoc:
|
||||
@@ -876,17 +876,19 @@ module ActionController #:nodoc:
|
||||
response.body << text
|
||||
else
|
||||
response.body = text
|
||||
end
|
||||
|
||||
if response.headers['Status'] == "200 OK" && response.body.size > 0
|
||||
response.headers['Etag'] = "\"#{MD5.new(text).to_s}\""
|
||||
|
||||
if request.headers['HTTP_IF_NONE_MATCH'] == response.headers['Etag']
|
||||
response.headers['Status'] = "304 Not Modified"
|
||||
response.body = ''
|
||||
if text.is_a?(String)
|
||||
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"
|
||||
response.body = ''
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
response.body
|
||||
end
|
||||
|
||||
|
||||
@@ -311,13 +311,13 @@ class RenderTest < Test::Unit::TestCase
|
||||
|
||||
def test_render_with_etag
|
||||
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']
|
||||
|
||||
|
||||
@request.headers["HTTP_IF_NONE_MATCH"] = expected_etag
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "304 Not Modified", @response.headers['Status']
|
||||
|
||||
|
||||
@request.headers["HTTP_IF_NONE_MATCH"] = "\"diftag\""
|
||||
get :render_hello_world_from_variable
|
||||
assert_equal "200 OK", @response.headers['Status']
|
||||
@@ -332,8 +332,8 @@ class RenderTest < Test::Unit::TestCase
|
||||
def assert_deprecated_render(&block)
|
||||
assert_deprecated(/render/, &block)
|
||||
end
|
||||
|
||||
|
||||
def etag_for(text)
|
||||
"\"#{MD5.new(text).to_s}\""
|
||||
%("#{Digest::MD5.hexdigest(text)}")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user