Skip to content
Closed
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
9 changes: 8 additions & 1 deletion lib/protocol/http/body/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,14 @@ def empty?

def read_next
if @input
return @input.read
# User's may forget to call #close...
if chunk = @input.read
return chunk
else
# So if we are at the end of the stream, we close it automatically:
@input.close
@input = nil
end
elsif @closed_read
raise IOError, "Stream is not readable, input has been closed!"
end
Expand Down
3 changes: 2 additions & 1 deletion test/protocol/http/body/streamable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@

with "#close" do
it "can close the body" do
expect(input).not.to receive(:close)
expect(input).to receive(:close)

expect(body.read).to be == "Hello"

body.close
end
end
Expand Down
Loading