Skip to content

Commit c8e7cc1

Browse files
committed
Return the buffer unless empty.
1 parent e19529e commit c8e7cc1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/protocol/http/body/stream.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ def gets(separator = NEWLINE, limit = nil, chomp: false)
263263
buffer = @buffer
264264
@buffer = nil
265265

266-
return @buffer
266+
# Return nil for empty buffers, otherwise return the content:
267+
if buffer && !buffer.empty?
268+
return buffer
269+
else
270+
return nil
271+
end
267272
end
268273
end
269274

test/protocol/http/body/stream.rb

+10
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@
240240
expect(stream.gets).to be == nil
241241
end
242242
end
243+
244+
with "incomplete line at the end" do
245+
let(:input) {Protocol::HTTP::Body::Buffered.new(["Hello\nWorld"])}
246+
247+
it "returns the remaining buffer when there is no more data to read" do
248+
expect(stream.gets).to be == "Hello\n"
249+
expect(stream.gets).to be == "World"
250+
expect(stream.gets).to be == nil
251+
end
252+
end
243253
end
244254

245255
with "#close_read" do

0 commit comments

Comments
 (0)