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/lib/action_dispatch/http | |
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/lib/action_dispatch/http')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 14 |
1 files changed, 11 insertions, 3 deletions
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 = " " |