File tree Expand file tree Collapse file tree 7 files changed +25
-15
lines changed Expand file tree Collapse file tree 7 files changed +25
-15
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ def close(error = nil)
40
40
@connection = nil
41
41
42
42
unless @finished
43
- connection . close
43
+ connection . close_read
44
44
end
45
45
end
46
46
@@ -86,7 +86,7 @@ def read
86
86
return chunk
87
87
else
88
88
# The connection has been closed before we have read the requested length:
89
- @connection . close
89
+ @connection . close_read
90
90
@connection = nil
91
91
end
92
92
end
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ def close(error = nil)
28
28
@connection = nil
29
29
30
30
unless @remaining == 0
31
- connection . close
31
+ connection . close_read
32
32
end
33
33
end
34
34
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def discard
26
26
@connection = nil
27
27
28
28
# Ensure no further requests can be read from the connection, as we are discarding the body which may not be fully read:
29
- connection . close
29
+ connection . close_read
30
30
end
31
31
end
32
32
@@ -39,8 +39,12 @@ def close(error = nil)
39
39
def read
40
40
@connection &.readpartial ( BLOCK_SIZE )
41
41
rescue EOFError
42
- @connection . receive_end_stream!
43
- @connection = nil
42
+ if connection = @connection
43
+ @connection = nil
44
+ connection . receive_end_stream!
45
+ end
46
+
47
+ return nil
44
48
end
45
49
46
50
def inspect
Original file line number Diff line number Diff line change @@ -186,6 +186,12 @@ def hijack!
186
186
return stream
187
187
end
188
188
189
+ def close_read
190
+ @persistent = false
191
+ @stream &.close_read
192
+ self . receive_end_stream!
193
+ end
194
+
189
195
# Close the connection and underlying stream.
190
196
def close
191
197
@persistent = false
Original file line number Diff line number Diff line change 28
28
29
29
with "#close" do
30
30
it "invokes close_read on the stream if closing without reading all chunks" do
31
- expect ( buffer ) . to receive ( :close )
31
+ expect ( buffer ) . to receive ( :close_read )
32
32
33
33
body . close
34
34
35
35
expect ( body ) . to be ( :empty? )
36
- expect ( connection ) . to be ( :closed ? )
36
+ expect ( connection ) . to be ( :half_closed_remote ? )
37
37
end
38
38
39
39
it "invokes close_read on the stream if closing with an error" do
40
- expect ( buffer ) . to receive ( :close )
40
+ expect ( buffer ) . to receive ( :close_read )
41
41
42
42
body . close ( EOFError )
43
43
44
44
expect ( body ) . to be ( :empty? )
45
- expect ( connection ) . to be ( :closed ? )
45
+ expect ( connection ) . to be ( :half_closed_remote ? )
46
46
end
47
47
end
48
48
96
96
97
97
body . close
98
98
99
- expect ( connection ) . to be ( :closed ? )
99
+ expect ( connection ) . to be ( :half_closed_remote ? )
100
100
end
101
101
end
102
102
106
106
it "raises error" do
107
107
expect { body . read } . to raise_exception ( EOFError )
108
108
109
- expect ( connection ) . to be ( :closed ? )
109
+ expect ( connection ) . to be ( :half_closed_remote ? )
110
110
end
111
111
end
112
112
end
Original file line number Diff line number Diff line change 29
29
body . close ( EOFError )
30
30
expect ( buffer ) . to be ( :closed? )
31
31
32
- expect ( connection ) . to be ( :closed ? )
32
+ expect ( connection ) . to be ( :half_closed_remote ? )
33
33
end
34
34
35
35
it "doesn't close the stream when EOF was reached" do
Original file line number Diff line number Diff line change 29
29
body . close ( EOFError )
30
30
expect ( buffer ) . to be ( :closed? )
31
31
32
- expect ( connection ) . to be ( :closed ? )
32
+ expect ( connection ) . to be ( :half_closed_remote ? )
33
33
end
34
34
35
35
it "closes the stream when EOF was reached" do
36
36
body . read
37
37
body . close ( EOFError )
38
38
expect ( buffer ) . to be ( :closed? )
39
39
40
- expect ( connection ) . to be ( :closed ? )
40
+ expect ( connection ) . to be ( :half_closed_remote ? )
41
41
end
42
42
end
43
43
You can’t perform that action at this time.
0 commit comments