@@ -128,14 +128,14 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
128
128
129
129
expect ( response . body ) . to be == 'text=Hello+World'
130
130
end
131
-
131
+
132
132
it "can use a ::Protocol::HTTP::Body::Readable body" do
133
133
readable = ::Protocol ::HTTP ::Body ::File . new ( File . open ( __FILE__ , 'r' ) , 0 ...128 )
134
-
134
+
135
135
response = Faraday . new do |builder |
136
136
builder . adapter :async_http
137
137
end . post ( bound_url , readable )
138
-
138
+
139
139
expect ( response . body ) . to be == File . read ( __FILE__ , 128 )
140
140
end
141
141
end
@@ -155,6 +155,41 @@ def get_response(url = bound_url, path = '/index', adapter_options: {})
155
155
expect ( config_block_invoked ) . to be == true
156
156
end
157
157
end
158
+
159
+ with "a streaming response" do
160
+ let ( :app ) do
161
+ Protocol ::HTTP ::Middleware . for do |request |
162
+ body = ::Async ::HTTP ::Body ::Writable . new
163
+
164
+ Async do
165
+ 3 . times do |i |
166
+ body . write ( "chunk#{ i } " )
167
+ end
168
+ ensure
169
+ body . close
170
+ end
171
+
172
+ Protocol ::HTTP ::Response [ 200 , { } , body ]
173
+ end
174
+ end
175
+
176
+ it "can stream response" do
177
+ client = Faraday . new do |builder |
178
+ builder . adapter :async_http
179
+ end
180
+
181
+ chunks = [ ]
182
+
183
+ response = client . get ( bound_url ) do |request |
184
+ request . options . on_data = proc do |chunk |
185
+ chunks << chunk
186
+ end
187
+ end
188
+
189
+ expect ( response . body ) . to be_nil
190
+ expect ( chunks ) . to be == [ "chunk0" , "chunk1" , "chunk2" ]
191
+ end
192
+ end
158
193
end
159
194
160
195
with "a remote http server" do
0 commit comments