module Ethon::Easies::Callbacks

def self.included(base)

def self.included(base)
  base.send(:attr_accessor, *[:response_body, :response_header])
end

def body_write_callback

Returns:
  • (Proc) - The callback.

Other tags:
    Example: Return the callback. -
def body_write_callback
  @body_write_callback ||= proc {|stream, size, num, object|
    @response_body << stream.read_string(size * num)
    size * num
  }
end

def header_write_callback

Returns:
  • (Proc) - The callback.

Other tags:
    Example: Return the callback. -
def header_write_callback
  @header_write_callback ||= proc {|stream, size, num, object|
    @response_header << stream.read_string(size * num)
    size * num
  }
end

def read_callback

Returns:
  • (Proc) - The callback.

Other tags:
    Example: Return the callback. -
def read_callback
  @read_callback
end

def set_callbacks

Other tags:
    Example: Set callbacks. -
def set_callbacks
  Curl.set_option(:writefunction, body_write_callback, handle)
  Curl.set_option(:headerfunction, header_write_callback, handle)
  @response_body = ""
  @response_header = ""
end

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
  @read_callback = proc {|stream, size, num, object|
    size = size * num
    left = body.bytesize - @request_body_read
    size = left if size > left
    if size > 0
      stream.write_string(body.byteslice(@request_body_read, size), size)
      @request_body_read += size
    end
    size
  }
  self.readfunction = read_callback
end