Skip to content

If the user reads exactly the content length, rack expects the input to be closed. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2024
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