-
Notifications
You must be signed in to change notification settings - Fork 19
browser fetcher
Fetcher is responsible for downloading resources and providing them as a buffer to the library. The library provides default fetcher based on libcurl on linux or other platform specific implementations, but the application may use its own.
The custom fetcher must be a class derived from Fetcher and must implement all pure virtual methods.
Methods Fetcher::initialize and Fetcher::finalize signals the fetcher to initialize or deinitialize itself.
They are provided mainly for convenience, and may found some use in a multithreaded environment.
The default fetcher on linux may be initialized multiple times without problems (so it can be used in multiple maps).
Method Fetcher::fetch is called by the library whenever it needs to download a resource.
It will pass a shared pointer to FetchTask.
FetchTask::Query::url is the url which should be downloaded and field FetchTask::Query::headers is an array of http headers, which should be added to the request (or overwrite it).
This method must not block.
Whenever the fetcher finishes a task (successfully or not), it should fill in all response-related fields it can, and call FetchTask::fetchDone.
Field FetchTask::Reply::code should contain the http status code.
If the client is beeing redirected, the new address goes to the field FetchTask::Reply::redirectUrl.
If the download was successful, buffer FetchTask::Reply::content should be filled with the response data (without any headers)
and FetchTask::Reply::contentType should be the content of http header Content-Type.
The method FetchTask::fetchDone may be called from any thread.
Note: if the fetcher receives a redirection (http status code between 300 and 399), it should not follow it, but proceed as if finished.
Note: the library may drop all references to the task before it is finished, therefore the fetcher must hold the shared pointer to the FetchTask, not just a plain pointer.