diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-13 17:48:56 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-07-13 17:48:56 -0700 |
commit | b37e29ec2db099b68ac3d80d1119774ae3688757 (patch) | |
tree | 47d04b449fa5e73e8d8cc487a30374a5a07eb90a /actionpack | |
parent | 48609420b814a66d263e19dd95064186de57cc40 (diff) | |
download | rails-b37e29ec2db099b68ac3d80d1119774ae3688757.tar.gz rails-b37e29ec2db099b68ac3d80d1119774ae3688757.tar.bz2 rails-b37e29ec2db099b68ac3d80d1119774ae3688757.zip |
move buffer caching on to the buffer
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/metal/data_streaming.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 14 |
3 files changed, 15 insertions, 7 deletions
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 <tt>render</tt>. def body - strings = [] - each { |part| strings << part.to_s } - strings.join + @stream.body end EMPTY = " " |