File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,11 @@ def stream?
57
57
def call ( stream )
58
58
while chunk = self . read
59
59
stream . write ( chunk )
60
+
61
+ # Flush the stream unless we are immediately expecting more data:
62
+ unless self . ready?
63
+ stream . flush
64
+ end
60
65
end
61
66
ensure
62
67
stream . close
Original file line number Diff line number Diff line change 3
3
# Released under the MIT License.
4
4
# Copyright, 2023-2024, by Samuel Williams.
5
5
6
+ require 'protocol/http/body/stream'
6
7
require 'protocol/http/body/readable'
7
8
8
9
describe Protocol ::HTTP ::Body ::Readable do
30
31
let ( :output ) { Protocol ::HTTP ::Body ::Buffered . new }
31
32
let ( :stream ) { Protocol ::HTTP ::Body ::Stream . new ( nil , output ) }
32
33
33
- it "can stream data" do
34
+ it "can stream (empty) data" do
34
35
body . call ( stream )
35
36
36
37
expect ( output ) . to be ( :empty? )
37
38
end
39
+
40
+ it "flushes the stream if it is not ready" do
41
+ chunks = [ "Hello World" ]
42
+
43
+ mock ( body ) do |mock |
44
+ mock . replace ( :read ) do
45
+ chunks . pop
46
+ end
47
+
48
+ mock . replace ( :ready? ) do
49
+ false
50
+ end
51
+ end
52
+
53
+ expect ( stream ) . to receive ( :flush )
54
+
55
+ body . call ( stream )
56
+ end
38
57
end
39
58
40
59
with '#join' do
You can’t perform that action at this time.
0 commit comments