Skip to content

Commit dbc874a

Browse files
committed
Invoke close on input stream when input is finished.
1 parent 8244dbf commit dbc874a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/protocol/http/body/stream.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,14 @@ def empty?
295295

296296
def read_next
297297
if @input
298-
return @input.read
298+
# User's may forget to call #close...
299+
if chunk = @input.read
300+
return chunk
301+
else
302+
# So if we are at the end of the stream, we close it automatically:
303+
@input.close
304+
@input = nil
305+
end
299306
elsif @closed_read
300307
raise IOError, "Stream is not readable, input has been closed!"
301308
end

test/protocol/http/body/streamable.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@
175175

176176
with "#close" do
177177
it "can close the body" do
178-
expect(input).not.to receive(:close)
178+
expect(input).to receive(:close)
179179

180180
expect(body.read).to be == "Hello"
181+
181182
body.close
182183
end
183184
end

0 commit comments

Comments
 (0)