File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -93,14 +93,18 @@ def read_next
9393 # https://github.com/socketry/async-http/issues/183
9494 if @body . empty?
9595 @body . close
96- @body = nil
96+ @closed = true
9797 end
9898
9999 return chunk
100100 else
101- # So if we are at the end of the stream, we close it automatically:
102- @body . close
103- @body = nil
101+ unless @closed
102+ # So if we are at the end of the stream, we close it automatically:
103+ @body . close
104+ @closed = true
105+ end
106+
107+ return nil
104108 end
105109 elsif @closed
106110 raise IOError , "Stream is not readable, input has been closed!"
Original file line number Diff line number Diff line change 4949 expect ( input . read ) . to be == sample_data . join
5050 expect ( input . read ) . to be == ""
5151
52- expect ( input . body ) . to be_nil
52+ expect ( input ) . to be ( :closed? )
53+ end
54+
55+ it "can rewind after reading all input" do
56+ expect ( input . read ) . to be == sample_data . join
57+ input . rewind
58+
59+ expect ( input . read ) . to be == sample_data . join
5360 end
5461
5562 it "can read exactly the content length" do
6976 expect ( input . read ( 3 ) ) . to be == "row"
7077 end
7178
79+ it "can rewind after reading partial input" do
80+ expect ( input . read ( 3 ) ) . to be == "The"
81+ input . rewind
82+
83+ expect ( input . read ( 3 ) ) . to be == "The"
84+ end
85+
7286 it "can read all input" do
7387 expect ( input . read ( 15 ) ) . to be == sample_data . join [ 0 ...15 ]
7488 expect ( input . read ) . to be == sample_data . join [ 15 ..-1 ]
7589
7690 expect ( input . read ( 1 ) ) . to be == nil
7791
78- expect ( input . body ) . to be_nil
92+ expect ( input ) . to be ( :closed? )
7993 end
8094
8195 it "can read partial input with buffer" do
You can’t perform that action at this time.
0 commit comments