These two functions create callback functions that can be used
to have the libcurl engine pass information to us
when it is available. basicTextGatherer
is a generator function that returns a closure which is
used to cumulate text provided in callbacks from the libcurl
engine when it reads the response from an HTTP request.
debugGatherer
can be used with the debugfunction
libcurl option in a call and the associated update
function is called whenever libcurl has information
about the header, data and general messages about the
request.
These functions return a list of functions.
Each time one calls basicTextGatherer
or
debugGatherer
, one gets a new, separate
collection of functions. However, each
collection of functions (or instance) shares
the variables across the functions and across calls.
This allows them to store data persistently across
the calls without using a global variable.
In this way, we can have multiple instances of the collection
of functions, with each instance updating its own local state
and not interfering with those of the others.
We use an S3 class named RCurlCallbackFunction
to indicate
that the collection of funcions can be used as a callback.
The update
function is the one that is actually used
as the callback function in the CURL option.
The value
function can be invoked to get the current
state that has been accumulated by the
update
function. This is typically used
when the request is complete.
One can reuse the same collection of functions across
different requests. The information will be cumulated.
Sometimes it is convenient to reuse the object but
reset the state to its original empty value, as it had
been created afresh. The reset
function in the collection
permits this.