Skip to content

Commit b155115

Browse files
committed
If the user reads exactly the content length, rack expects the input to be closed.
1 parent c65e544 commit b155115

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/protocol/rack/input.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ def read_next
8989
if @body
9090
# User's may forget to call #close...
9191
if chunk = @body.read
92+
# If the user reads exactly the content length, we close the stream automatically:
93+
# https://github.com/socketry/async-http/issues/183
94+
if @body.empty?
95+
@body.close
96+
@body = nil
97+
end
98+
9299
return chunk
93100
else
94101
# So if we are at the end of the stream, we close it automatically:

test/protocol/rack/input.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
expect(input.body).to be_nil
5353
end
5454

55+
it "can read exactly the content length" do
56+
expect(body).to receive(:close)
57+
58+
expect(input.read(sample_data.join.bytesize)).to be == sample_data.join
59+
end
60+
5561
it "can read no input" do
5662
expect(input.read(0)).to be == ""
5763
end

0 commit comments

Comments
 (0)