Skip to content

Commit 4764c5a

Browse files
authored
Check if the input is closed before raise IOError (#32)
1 parent 8046af7 commit 4764c5a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/protocol/http/body/stream.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def initialize(input = nil, output = Buffered.new)
1919
# Will hold remaining data in `#read`.
2020
@buffer = nil
2121
@closed = false
22+
@closed_read = false
2223
end
2324

2425
attr :input
@@ -146,6 +147,7 @@ def flush
146147
end
147148

148149
def close_read
150+
@closed_read = true
149151
@input&.close
150152
@input = nil
151153
end
@@ -181,8 +183,7 @@ def empty?
181183
def read_next
182184
if @input
183185
return @input.read
184-
else
185-
@input = nil
186+
elsif @closed_read
186187
raise IOError, "Stream is not readable, input has been closed!"
187188
end
188189
end

0 commit comments

Comments
 (0)