Module: Ethon::Easy::Callbacks Private
- Included in:
- Ethon::Easy
- Defined in:
- lib/ethon/easy/callbacks.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
This module contains all the logic around the callbacks, which are needed to interact with libcurl.
Class Method Summary collapse
-
.included(base) ⇒ Object
private
:nodoc:.
Instance Method Summary collapse
-
#body_write_callback ⇒ Proc
private
Returns the body write callback.
-
#header_write_callback ⇒ Proc
private
Returns the header write callback.
-
#read_callback ⇒ Proc
private
Returns the body read callback.
-
#set_callbacks ⇒ Object
private
Set writefunction and headerfunction callback.
-
#set_read_callback(body) ⇒ Object
private
Set the read callback.
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
11 12 13 |
# File 'lib/ethon/easy/callbacks.rb', line 11 def self.included(base) base.send(:attr_accessor, *[:response_body, :response_headers]) end |
Instance Method Details
#body_write_callback ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the body write callback.
34 35 36 37 38 39 |
# File 'lib/ethon/easy/callbacks.rb', line 34 def body_write_callback @body_write_callback ||= proc {|stream, size, num, object| @response_body << stream.read_string(size * num) size * num } end |
#header_write_callback ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the header write callback.
47 48 49 50 51 52 |
# File 'lib/ethon/easy/callbacks.rb', line 47 def header_write_callback @header_write_callback ||= proc {|stream, size, num, object| @response_headers << stream.read_string(size * num) size * num } end |
#read_callback ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the body read callback.
84 85 86 |
# File 'lib/ethon/easy/callbacks.rb', line 84 def read_callback @read_callback end |
#set_callbacks ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set writefunction and headerfunction callback. They are called by libcurl in order to provide the header and the body from the request.
21 22 23 24 25 26 |
# File 'lib/ethon/easy/callbacks.rb', line 21 def set_callbacks Curl.set_option(:writefunction, body_write_callback, handle) Curl.set_option(:headerfunction, header_write_callback, handle) @response_body = "" @response_headers = "" end |
#set_read_callback(body) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set the read callback. This callback is used by libcurl to read data when performing a PUT request.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ethon/easy/callbacks.rb', line 61 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.respond_to?(:byteslice) ? body.byteslice(@request_body_read, size) : body[@request_body_read, size], size ) @request_body_read += size end size } self.readfunction = read_callback end |