Skip to content

Commit

Permalink
If the user reads exactly the content length, rack expects the input …
Browse files Browse the repository at this point in the history
…to be closed.
  • Loading branch information
ioquatix committed Oct 11, 2024
1 parent c65e544 commit b155115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit b155115

Please sign in to comment.