From b37e29ec2db099b68ac3d80d1119774ae3688757 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 13 Jul 2015 17:48:56 -0700 Subject: move buffer caching on to the buffer --- actionpack/lib/action_controller/metal/data_streaming.rb | 4 ++++ actionpack/lib/action_controller/test_case.rb | 4 ---- actionpack/lib/action_dispatch/http/response.rb | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb index 1abd8d3a33..0abfd629aa 100644 --- a/actionpack/lib/action_controller/metal/data_streaming.rb +++ b/actionpack/lib/action_controller/metal/data_streaming.rb @@ -85,6 +85,10 @@ module ActionController #:nodoc: @to_path = path end + def body + File.binread(to_path) + end + # Stream the file's contents if Rack::Sendfile isn't present. def each File.open(to_path, 'rb') do |file| diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 43c481339a..ad9836f122 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -136,10 +136,6 @@ module ActionController end class LiveTestResponse < Live::Response - def body - @body ||= super - end - # Was the response successful? alias_method :success?, :successful? diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index c5939adb9f..eab7d0ab57 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -80,11 +80,21 @@ module ActionDispatch # :nodoc: @response = response @buf = buf @closed = false + @str_body = nil + end + + def body + @str_body ||= begin + buf = '' + each { |chunk| buf << chunk } + buf + end end def write(string) raise IOError, "closed stream" if closed? + @str_body = nil @response.commit! @buf.push string end @@ -222,9 +232,7 @@ module ActionDispatch # :nodoc: # Returns the content of the response as a string. This contains the contents # of any calls to render. def body - strings = [] - each { |part| strings << part.to_s } - strings.join + @stream.body end EMPTY = " " -- cgit v1.2.3