Skip to content

Commit

Permalink
move buffer caching on to the buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jul 14, 2015
1 parent 4860942 commit b37e29e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions actionpack/lib/action_controller/metal/data_streaming.rb
Expand Up @@ -85,6 +85,10 @@ def initialize(path)
@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|
Expand Down
4 changes: 0 additions & 4 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -136,10 +136,6 @@ class TestResponse < ActionDispatch::TestResponse
end

class LiveTestResponse < Live::Response
def body
@body ||= super
end

# Was the response successful?
alias_method :success?, :successful?

Expand Down
14 changes: 11 additions & 3 deletions actionpack/lib/action_dispatch/http/response.rb
Expand Up @@ -80,11 +80,21 @@ def initialize(response, buf)
@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
Expand Down Expand Up @@ -222,9 +232,7 @@ def message
# 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 = " "
Expand Down

0 comments on commit b37e29e

Please sign in to comment.