lib/httpx/plugins/stream.rb in httpx-1.2.4 vs lib/httpx/plugins/stream.rb in httpx-1.2.6
- old
+ new
@@ -14,12 +14,21 @@
@request.stream = self
begin
@on_chunk = block
+ if @request.response
+ # if we've already started collecting the payload, yield it first
+ # before proceeding.
+ body = @request.response.body
+
+ body.each do |chunk|
+ on_chunk(chunk)
+ end
+ end
+
response.raise_for_status
ensure
- response.close if @response
@on_chunk = nil
end
end
def each_line