Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/protocol/rack/body/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def close(error = nil)
# @yields {|chunk| ...}
# @parameter chunk [String] A chunk of the response body.
def each(&block)
@body.each(&block)
@body&.each(&block)
rescue => error
raise
ensure
Expand Down
1 change: 1 addition & 0 deletions releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Respect the result of rewinding the underlying request body.
- Avoid enumerating a response body after it has been closed.

## v0.22.1

Expand Down
10 changes: 10 additions & 0 deletions test/protocol/rack/body/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
end
end.to raise_exception(RuntimeError, message: be =~ /Bad Enumerable/)
end

it "does not enumerate after being closed" do
body = subject.new(["Hello World"], 11)
body.close

chunks = []
body.each{|chunk| chunks << chunk}

expect(chunks).to be(:empty?)
end
end

with "#call" do
Expand Down
Loading