Skip to content

Commit cc05882

Browse files
committed
Revert back to close_read implementation/state transition.
1 parent 50b1201 commit cc05882

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

lib/protocol/http1/body/chunked.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def close(error = nil)
4040
@connection = nil
4141

4242
unless @finished
43-
connection.close
43+
connection.close_read
4444
end
4545
end
4646

@@ -86,7 +86,7 @@ def read
8686
return chunk
8787
else
8888
# The connection has been closed before we have read the requested length:
89-
@connection.close
89+
@connection.close_read
9090
@connection = nil
9191
end
9292
end

lib/protocol/http1/body/fixed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def close(error = nil)
2828
@connection = nil
2929

3030
unless @remaining == 0
31-
connection.close
31+
connection.close_read
3232
end
3333
end
3434

lib/protocol/http1/body/remainder.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def discard
2626
@connection = nil
2727

2828
# 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
3030
end
3131
end
3232

@@ -39,8 +39,12 @@ def close(error = nil)
3939
def read
4040
@connection&.readpartial(BLOCK_SIZE)
4141
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
4448
end
4549

4650
def inspect

lib/protocol/http1/connection.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ def hijack!
186186
return stream
187187
end
188188

189+
def close_read
190+
@persistent = false
191+
@stream&.close_read
192+
self.receive_end_stream!
193+
end
194+
189195
# Close the connection and underlying stream.
190196
def close
191197
@persistent = false

test/protocol/http1/body/chunked.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@
2828

2929
with "#close" do
3030
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)
3232

3333
body.close
3434

3535
expect(body).to be(:empty?)
36-
expect(connection).to be(:closed?)
36+
expect(connection).to be(:half_closed_remote?)
3737
end
3838

3939
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)
4141

4242
body.close(EOFError)
4343

4444
expect(body).to be(:empty?)
45-
expect(connection).to be(:closed?)
45+
expect(connection).to be(:half_closed_remote?)
4646
end
4747
end
4848

@@ -96,7 +96,7 @@
9696

9797
body.close
9898

99-
expect(connection).to be(:closed?)
99+
expect(connection).to be(:half_closed_remote?)
100100
end
101101
end
102102

@@ -106,7 +106,7 @@
106106
it "raises error" do
107107
expect{body.read}.to raise_exception(EOFError)
108108

109-
expect(connection).to be(:closed?)
109+
expect(connection).to be(:half_closed_remote?)
110110
end
111111
end
112112
end

test/protocol/http1/body/fixed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
body.close(EOFError)
3030
expect(buffer).to be(:closed?)
3131

32-
expect(connection).to be(:closed?)
32+
expect(connection).to be(:half_closed_remote?)
3333
end
3434

3535
it "doesn't close the stream when EOF was reached" do

test/protocol/http1/body/remainder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
body.close(EOFError)
3030
expect(buffer).to be(:closed?)
3131

32-
expect(connection).to be(:closed?)
32+
expect(connection).to be(:half_closed_remote?)
3333
end
3434

3535
it "closes the stream when EOF was reached" do
3636
body.read
3737
body.close(EOFError)
3838
expect(buffer).to be(:closed?)
3939

40-
expect(connection).to be(:closed?)
40+
expect(connection).to be(:half_closed_remote?)
4141
end
4242
end
4343

0 commit comments

Comments
 (0)