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: 7 additions & 0 deletions lib/protocol/rack/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ def read_next
if @body
# User's may forget to call #close...
if chunk = @body.read
# If the user reads exactly the content length, we close the stream automatically:
# https://github.com/socketry/async-http/issues/183
if @body.empty?
@body.close
@body = nil
end

return chunk
else
# So if we are at the end of the stream, we close it automatically:
Expand Down
6 changes: 6 additions & 0 deletions test/protocol/rack/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
expect(input.body).to be_nil
end

it "can read exactly the content length" do
expect(body).to receive(:close)

expect(input.read(sample_data.join.bytesize)).to be == sample_data.join
end

it "can read no input" do
expect(input.read(0)).to be == ""
end
Expand Down
Loading