lib/httpx/plugins/stream.rb in httpx-1.1.2 vs lib/httpx/plugins/stream.rb in httpx-1.1.3
- old
+ new
@@ -9,12 +9,10 @@
end
def each(&block)
return enum_for(__method__) unless block
- raise Error, "response already streamed" if @response
-
@request.stream = self
begin
@on_chunk = block
@@ -117,11 +115,14 @@
attr_accessor :stream
end
module ResponseMethods
def stream
- @request.stream
+ request = @request.root_request if @request.respond_to?(:root_request)
+ request ||= @request
+
+ request.stream
end
end
module ResponseBodyMethods
def initialize(*)
@@ -130,10 +131,16 @@
end
def write(chunk)
return super unless @stream
- @stream.on_chunk(chunk.to_s.dup)
+ return 0 if chunk.empty?
+
+ chunk = decode_chunk(chunk)
+
+ @stream.on_chunk(chunk.dup)
+
+ chunk.size
end
private
def transition(*)