module Ethon::Easy::Callbacks

def set_read_callback(body)

Parameters:
  • body (String) -- The body.

Other tags:
    Example: Set the callback. -
def set_read_callback(body)
  @request_body_read = 0
  readfunction do |stream, size, num, object|
    size = size * num
    body_size = if body.respond_to?(:bytesize)
      body.bytesize
    elsif body.respond_to?(:size)
      body.size
    elsif body.is_a?(File)
      File.size(body.path)
    end
    left = body_size - @request_body_read
    size = left if size > left
    if size > 0
      chunk = if body.respond_to?(:byteslice)
        body.byteslice(@request_body_read, size)
      elsif body.respond_to?(:read)
        body.read(size)
      else
        body[@request_body_read, size]
      end
      stream.write_string(
        chunk, size
      )
      @request_body_read += size
    end
    size
  end
end