lib/httpx/response.rb in httpx-0.23.4 vs lib/httpx/response.rb in httpx-0.24.0
- old
+ new
@@ -7,10 +7,11 @@
require "forwardable"
module HTTPX
class Response
extend Forwardable
+ include Callbacks
attr_reader :status, :headers, :body, :version
def_delegator :@body, :to_s
@@ -137,19 +138,29 @@
@length = 0
@buffer = nil
@state = :idle
end
+ def initialize_dup(other)
+ super
+
+ @buffer = other.instance_variable_get(:@buffer).dup
+ end
+
def closed?
@state == :closed
end
def write(chunk)
return if @state == :closed
- @length += chunk.bytesize
+ size = chunk.bytesize
+ @length += size
transition
@buffer.write(chunk)
+
+ @response.emit(:chunk_received, chunk)
+ size
end
def read(*args)
return unless @buffer