Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.2.8 #2140

Open
wants to merge 3 commits into
base: 2-2-stable
Choose a base branch
from
Open

2.2.8 #2140

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/rack/mock.rb
Expand Up @@ -212,8 +212,15 @@ def body
# end
buffer = String.new

super.each do |chunk|
buffer << chunk
body = super
body = body.body if body.respond_to?(:body)

if body.respond_to?(:each)
body.each do |chunk|
buffer << chunk
end
else
buffer = body.to_s
end

return buffer
Expand Down
45 changes: 25 additions & 20 deletions lib/rack/response.rb
Expand Up @@ -254,37 +254,42 @@ def etag
get_header ETAG
end

def etag=(v)
set_header ETAG, v
def etag=(value)
set_header ETAG, value
end

protected

def buffered_body!
return if @buffered

if @body.is_a?(Array)
# The user supplied body was an array:
@body = @body.compact
@body.each do |part|
@length += part.to_s.bytesize
end
else
# Turn the user supplied body into a buffered array:
body = @body
@body = Array.new

body.each do |part|
@writer.call(part.to_s)
if @buffered.nil?
if @body.is_a?(Array)
# The user supplied body was an array:
@body = @body.compact
@body.each do |part|
@length += part.to_s.bytesize
end
elsif @body.respond_to?(:each)
# Turn the user supplied body into a buffered array:
body = @body
@body = Array.new

body.each do |part|
@writer.call(part.to_s)
end

body.close if body.respond_to?(:close)

@buffered = true
else
@buffered = false
end

body.close if body.respond_to?(:close)
end

@buffered = true
return @buffered
end

def append(chunk)
chunk = chunk.dup unless chunk.frozen?
@body << chunk

unless chunked?
Expand Down