diff --git a/lib/protocol/http/body/stream.rb b/lib/protocol/http/body/stream.rb index 34e96cd..742e18e 100644 --- a/lib/protocol/http/body/stream.rb +++ b/lib/protocol/http/body/stream.rb @@ -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 diff --git a/test/protocol/http/body/streamable.rb b/test/protocol/http/body/streamable.rb index d62b702..e6bd189 100644 --- a/test/protocol/http/body/streamable.rb +++ b/test/protocol/http/body/streamable.rb @@ -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