Skip to content
Merged
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
7 changes: 6 additions & 1 deletion lib/protocol/http/body/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ def gets(separator = NEWLINE, limit = nil, chomp: false)
buffer = @buffer
@buffer = nil

return @buffer
# Return nil for empty buffers, otherwise return the content:
if buffer && !buffer.empty?
return buffer
else
return nil
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/protocol/http/body/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@
expect(stream.gets).to be == nil
end
end

with "incomplete line at the end" do
let(:input) {Protocol::HTTP::Body::Buffered.new(["Hello\nWorld"])}

it "returns the remaining buffer when there is no more data to read" do
expect(stream.gets).to be == "Hello\n"
expect(stream.gets).to be == "World"
expect(stream.gets).to be == nil
end
end
end

with "#close_read" do
Expand Down
Loading