aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/response.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-03-24 12:10:38 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-24 12:10:38 +0000
commit4687306c2c1d94b0db6d66625867d881838b76d6 (patch)
treeec54e4d91113e8d3b6a481912a687aa97e3c63e2 /actionpack/lib/action_controller/response.rb
parent2f340d050b0327d809b10bb661ee0dd127777256 (diff)
parent6ed42ebdff05f9d28a60e91093d8f9afad03a958 (diff)
downloadrails-4687306c2c1d94b0db6d66625867d881838b76d6.tar.gz
rails-4687306c2c1d94b0db6d66625867d881838b76d6.tar.bz2
rails-4687306c2c1d94b0db6d66625867d881838b76d6.zip
Merge commit 'mainstream/master'
Conflicts: railties/guides/images/fxn.jpg railties/guides/rails_guides/generator.rb
Diffstat (limited to 'actionpack/lib/action_controller/response.rb')
-rw-r--r--actionpack/lib/action_controller/response.rb41
1 files changed, 30 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb
index ccff473df0..febe4ccf29 100644
--- a/actionpack/lib/action_controller/response.rb
+++ b/actionpack/lib/action_controller/response.rb
@@ -40,14 +40,28 @@ module ActionController # :nodoc:
delegate :default_charset, :to => 'ActionController::Base'
def initialize
- @status = 200
+ super
@header = Rack::Utils::HeaderHash.new(DEFAULT_HEADERS)
+ @session, @assigns = [], []
+ end
- @writer = lambda { |x| @body << x }
- @block = nil
+ def body
+ str = ''
+ each { |part| str << part.to_s }
+ str
+ end
- @body = "",
- @session, @assigns = [], []
+ def body=(body)
+ @body =
+ if body.is_a?(String)
+ [body]
+ else
+ body
+ end
+ end
+
+ def body_parts
+ @body
end
def location; headers['Location'] end
@@ -152,7 +166,7 @@ module ActionController # :nodoc:
@writer = lambda { |x| callback.call(x) }
@body.call(self, self)
elsif @body.is_a?(String)
- @body.each_line(&callback)
+ callback.call(@body)
else
@body.each(&callback)
end
@@ -162,7 +176,8 @@ module ActionController # :nodoc:
end
def write(str)
- @writer.call str.to_s
+ str = str.to_s
+ @writer.call str
str
end
@@ -186,7 +201,7 @@ module ActionController # :nodoc:
if request && request.etag_matches?(etag)
self.status = '304 Not Modified'
- self.body = ''
+ self.body = []
end
set_conditional_cache_control!
@@ -195,7 +210,11 @@ module ActionController # :nodoc:
def nonempty_ok_response?
ok = !status || status.to_s[0..2] == '200'
- ok && body.is_a?(String) && !body.empty?
+ ok && string_body?
+ end
+
+ def string_body?
+ !body_parts.respond_to?(:call) && body_parts.any? && body_parts.all? { |part| part.is_a?(String) }
end
def set_conditional_cache_control!
@@ -216,8 +235,8 @@ module ActionController # :nodoc:
headers.delete('Content-Length')
elsif length = headers['Content-Length']
headers['Content-Length'] = length.to_s
- elsif !body.respond_to?(:call) && (!status || status.to_s[0..2] != '304')
- headers["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
+ elsif string_body? && (!status || status.to_s[0..2] != '304')
+ headers["Content-Length"] = Rack::Utils.bytesize(body).to_s
end
end