File tree Expand file tree Collapse file tree 3 files changed +7
-2
lines changed Expand file tree Collapse file tree 3 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ def read
57
57
if length == 0
58
58
read_trailer
59
59
60
+ # The final chunk has been read and the stream is now closed:
60
61
@stream = nil
61
62
@finished = true
62
63
@@ -75,6 +76,7 @@ def read
75
76
return chunk
76
77
end
77
78
79
+ # If the stream has been closed before we have read the final chunk, raise an error:
78
80
raise EOFError , "Stream closed before expected length was read!"
79
81
end
80
82
end
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ module Body
11
11
class Fixed < HTTP ::Body ::Readable
12
12
def initialize ( stream , length )
13
13
@stream = stream
14
+
14
15
@length = length
15
16
@remaining = length
16
17
end
@@ -39,14 +40,15 @@ def close(error = nil)
39
40
def read
40
41
if @remaining > 0
41
42
if @stream
42
- # `readpartial` will raise `EOFError` if the stream is closed/ finished:
43
+ # `readpartial` will raise `EOFError` if the stream is finished, or `IOError` if the stream is closed.
43
44
if chunk = @stream . readpartial ( @remaining )
44
45
@remaining -= chunk . bytesize
45
46
46
47
return chunk
47
48
end
48
49
end
49
50
51
+ # If the stream has been closed before we have read the expected length, raise an error:
50
52
raise EOFError , "Stream closed before expected length was read!"
51
53
end
52
54
end
Original file line number Diff line number Diff line change 8
8
module Protocol
9
9
module HTTP1
10
10
module Body
11
+ # A body that reads all remaining data from the stream.
11
12
class Remainder < HTTP ::Body ::Readable
12
13
BLOCK_SIZE = 1024 * 64
13
14
@@ -22,8 +23,8 @@ def empty?
22
23
23
24
def close ( error = nil )
24
25
if @stream
25
- @stream . close_read
26
26
# We can't really do anything in this case except close the connection.
27
+ @stream . close_read
27
28
@stream = nil
28
29
end
29
30
You can’t perform that action at this time.
0 commit comments