Skip to content

Commit b37e29e

Browse files
committed
move buffer caching on to the buffer
1 parent 4860942 commit b37e29e

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

actionpack/lib/action_controller/metal/data_streaming.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def initialize(path)
8585
@to_path = path
8686
end
8787

88+
def body
89+
File.binread(to_path)
90+
end
91+
8892
# Stream the file's contents if Rack::Sendfile isn't present.
8993
def each
9094
File.open(to_path, 'rb') do |file|

actionpack/lib/action_controller/test_case.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ class TestResponse < ActionDispatch::TestResponse
136136
end
137137

138138
class LiveTestResponse < Live::Response
139-
def body
140-
@body ||= super
141-
end
142-
143139
# Was the response successful?
144140
alias_method :success?, :successful?
145141

actionpack/lib/action_dispatch/http/response.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,21 @@ def initialize(response, buf)
8080
@response = response
8181
@buf = buf
8282
@closed = false
83+
@str_body = nil
84+
end
85+
86+
def body
87+
@str_body ||= begin
88+
buf = ''
89+
each { |chunk| buf << chunk }
90+
buf
91+
end
8392
end
8493

8594
def write(string)
8695
raise IOError, "closed stream" if closed?
8796

97+
@str_body = nil
8898
@response.commit!
8999
@buf.push string
90100
end
@@ -222,9 +232,7 @@ def message
222232
# Returns the content of the response as a string. This contains the contents
223233
# of any calls to <tt>render</tt>.
224234
def body
225-
strings = []
226-
each { |part| strings << part.to_s }
227-
strings.join
235+
@stream.body
228236
end
229237

230238
EMPTY = " "

0 commit comments

Comments
 (0)