diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-29 17:02:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-07-29 17:02:00 -0700 |
commit | a6bdae1c19f1a6ace1f6504b2716c8e8eae0d64f (patch) | |
tree | 628bf9c232e9b383f9b8e2956eb300939f7ab7eb | |
parent | 19e68e9d472f81f9856cd10fba4ba75f653c90e4 (diff) | |
download | rails-a6bdae1c19f1a6ace1f6504b2716c8e8eae0d64f.tar.gz rails-a6bdae1c19f1a6ace1f6504b2716c8e8eae0d64f.tar.bz2 rails-a6bdae1c19f1a6ace1f6504b2716c8e8eae0d64f.zip |
flushing output should write to the stream rather than mutating the response object
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 20 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/capture_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/send_file_test.rb | 6 |
3 files changed, 16 insertions, 12 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 912463bc0e..b638000fc5 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -42,7 +42,7 @@ module ActionDispatch # :nodoc: alias_method :headers, :header delegate :[], :[]=, :to => :@header - delegate :each, :to => :@body + delegate :each, :to => :@stream # Sets the HTTP response's content MIME type. For example, in the controller # you could write this: @@ -106,8 +106,6 @@ module ActionDispatch # :nodoc: @committed = false @content_type = nil @charset = nil - @stream = build_buffer self, @body - if content_type = self[CONTENT_TYPE] type, charset = content_type.split(/;\s*charset=/) @@ -162,14 +160,14 @@ module ActionDispatch # :nodoc: def respond_to?(method) if method.to_sym == :to_path - @body.respond_to?(:to_path) + stream.respond_to?(:to_path) else super end end def to_path - @body.to_path + stream.to_path end def body @@ -183,11 +181,17 @@ module ActionDispatch # :nodoc: def body=(body) @blank = true if body == EMPTY - @body = munge_body_object(body) + if body.respond_to?(:to_path) + @stream = body + else + @stream = build_buffer self, munge_body_object(body) + end end def body_parts - @body + parts = [] + @stream.each { |x| parts << x } + parts end def set_cookie(key, value) @@ -208,7 +212,7 @@ module ActionDispatch # :nodoc: end def close - @body.close if @body.respond_to?(:close) + stream.close end def to_a diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 9186855319..651d6e4d16 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -213,7 +213,7 @@ module ActionView # Add the output buffer to the response body and start a new one. def flush_output_buffer #:nodoc: if output_buffer && !output_buffer.empty? - response.body_parts << output_buffer + response.stream.write output_buffer self.output_buffer = output_buffer.respond_to?(:clone_empty) ? output_buffer.clone_empty : output_buffer[0, 0] nil end diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 6fc3556e31..97ede35317 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -51,14 +51,14 @@ class SendFileTest < ActionController::TestCase response = nil assert_nothing_raised { response = process('file') } assert_not_nil response - assert_respond_to response.body_parts, :each - assert_respond_to response.body_parts, :to_path + assert_respond_to response.stream, :each + assert_respond_to response.stream, :to_path require 'stringio' output = StringIO.new output.binmode output.string.force_encoding(file_data.encoding) - assert_nothing_raised { response.body_parts.each { |part| output << part.to_s } } + response.body_parts.each { |part| output << part.to_s } assert_equal file_data, output.string end |