Skip to content

Commit

Permalink
Invoke close on input stream when input is finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 3, 2024
1 parent 8244dbf commit dbc874a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit dbc874a

Please sign in to comment.