diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-05-06 14:22:05 -0500 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-05-06 14:22:05 -0500 |
commit | 21a3b180f11e49e1cd296aacba3bec8120dc7c2e (patch) | |
tree | 80053ca78b371d2f9647626c38d328dcb8a4f302 /actionpack/lib/action_dispatch | |
parent | 40d5c3370f8e5e0d3d03a7a25a64fde5122a069e (diff) | |
parent | b43158afba7fb4de6a3530d4f4e940f0c89bd057 (diff) | |
download | rails-21a3b180f11e49e1cd296aacba3bec8120dc7c2e.tar.gz rails-21a3b180f11e49e1cd296aacba3bec8120dc7c2e.tar.bz2 rails-21a3b180f11e49e1cd296aacba3bec8120dc7c2e.zip |
Merge pull request #24029 from rthbound/dont-call-each-when-calling-body-on-response
Dont call each when calling body on response to fix #23964
Fixes #23964
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index fa4c54701a..1515d59df3 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -68,7 +68,13 @@ module ActionDispatch # :nodoc: alias_method :headers, :header delegate :[], :[]=, :to => :@header - delegate :each, :to => :@stream + + def each(&block) + sending! + x = @stream.each(&block) + sent! + x + end CONTENT_TYPE = "Content-Type".freeze SET_COOKIE = "Set-Cookie".freeze @@ -97,10 +103,10 @@ module ActionDispatch # :nodoc: def body @str_body ||= begin - buf = '' - each { |chunk| buf << chunk } - buf - end + buf = '' + each { |chunk| buf << chunk } + buf + end end def write(string) @@ -112,10 +118,13 @@ module ActionDispatch # :nodoc: end def each(&block) - @response.sending! - x = @buf.each(&block) - @response.sent! - x + if @str_body + return enum_for(:each) unless block_given? + + yield @str_body + else + each_chunk(&block) + end end def abort @@ -129,6 +138,12 @@ module ActionDispatch # :nodoc: def closed? @closed end + + private + + def each_chunk(&block) + @buf.each(&block) # extract into own method + end end def self.create(status = 200, header = {}, body = [], default_headers: self.default_headers) |