class Seahorse::Client::Plugins::RequestCallback::OptionHandler

@api private

def add_response_events(on_chunk_received, context)

def add_response_events(on_chunk_received, context)
  shared_data = {bytes_received: 0}
  context.http_response.on_headers do |_status, headers|
    shared_data[:content_length] = headers['content-length']&.to_i
  end
  context.http_response.on_data do |chunk|
    shared_data[:bytes_received] += chunk.bytesize if chunk && chunk.respond_to?(:bytesize)
    on_chunk_received.call(chunk, shared_data[:bytes_received], shared_data[:content_length])
  end
end

def call(context)

def call(context)
  if context.params.is_a?(Hash) && context.params[:on_chunk_sent]
    on_chunk_sent = context.params.delete(:on_chunk_sent)
  end
  on_chunk_sent = context.config.on_chunk_sent if on_chunk_sent.nil?
  context[:on_chunk_sent] = on_chunk_sent if on_chunk_sent
  if context.params.is_a?(Hash) && context.params[:on_chunk_received]
    on_chunk_received = context.params.delete(:on_chunk_received)
  end
  on_chunk_received = context.config.on_chunk_received if on_chunk_received.nil?
  add_response_events(on_chunk_received, context) if on_chunk_received
  @handler.call(context)
end