Belle II Software
release-08-01-10
|
Simple class to encapsulate libcurl as used by the ConditionsDatabase. More...
#include <Downloader.h>
Public Member Functions | |
Downloader ()=default | |
Create a new payload downloader. | |
~Downloader () | |
Destructor. | |
bool | startSession () |
Start a new curl session if none is active at the moment. More... | |
void | finishSession () |
Finish an existing curl session if any is active at the moment. | |
ScopeGuard | ensureSession () |
Make sure there's an active session and return a ScopeGuard object that closes the session on destruction in case a new session was created;. | |
unsigned int | getConnectionTimeout () const |
Get the timeout to wait for connections in seconds, 0 means the built in curl default. | |
unsigned int | getStalledTimeout () const |
Get the timeout to wait for stalled connections (<10KB/s), 0 means no timeout. | |
unsigned int | getMaxRetries () const |
Get the number of retries to perform when downloading fails with HTTP response code >=500, 0 means no retries. | |
unsigned int | getBackoffFactor () const |
Get the backoff factor for retries in seconds. | |
void | setConnectionTimeout (unsigned int timeout) |
Set the timeout to wait for connections in seconds, 0 means built in curl default. | |
void | setStalledTimeout (unsigned int timeout) |
Set the timeout to wait for stalled connections (<10KB/s), 0 disables timeout. | |
void | setMaxRetries (unsigned int retries) |
Set the number of retries to perform when downloading fails with HTTP response code >=500, 0 disables retry. | |
void | setBackoffFactor (unsigned int factor) |
Set the backoff factor for retries in seconds. More... | |
bool | download (const std::string &url, std::ostream &stream, bool silentOnMissing=false) |
get an url and save the content to stream This function raises exceptions when there are any problems More... | |
bool | verifyChecksum (std::istream &input, const std::string &checksum) |
check the digest of a stream More... | |
std::string | escapeString (const std::string &text) |
Escape a string to make it safe to be used in web requests. | |
std::string | joinWithSlash (const std::string &base, const std::string &second) |
Join two strings and make sure that there is exactly one '/' between them. | |
Static Public Member Functions | |
static Downloader & | getDefaultInstance () |
Return the default instance. More... | |
Static Private Member Functions | |
static std::string | calculateChecksum (std::istream &input) |
calculate the digest/checksum on a given string. More... | |
Private Attributes | |
std::unique_ptr< CurlSession > | m_session |
curl session handle | |
unsigned int | m_connectionTimeout {60} |
Timeout to wait for connections in seconds. | |
unsigned int | m_stalledTimeout {60} |
Timeout to wait for stalled connections (<10KB/s) | |
unsigned int | m_maxRetries {5} |
Number of retries to perform when downloading fails with HTTP response code >=500. | |
unsigned int | m_backoffFactor {5} |
Backoff factor for retries in seconds. | |
Static Private Attributes | |
static bool | s_globalInit {false} |
flag to indicate whether curl has been initialized already | |
Simple class to encapsulate libcurl as used by the ConditionsDatabase.
Definition at line 21 of file Downloader.h.
|
staticprivate |
calculate the digest/checksum on a given string.
input | input stream containing the data |
Definition at line 224 of file Downloader.cc.
bool download | ( | const std::string & | url, |
std::ostream & | stream, | ||
bool | silentOnMissing = false |
||
) |
get an url and save the content to stream This function raises exceptions when there are any problems
url | the url to download |
stream | the stream to save the output to |
silentOnMissing | if true do not emit a warning on 404 Not Found but just return false silently. Useful when checking if a file exists on the server |
Definition at line 258 of file Downloader.cc.
|
static |
Return the default instance.
There can be multiple instances without problem but we provide a default one to allow for better pipelining support
Definition at line 133 of file Downloader.cc.
|
inline |
Set the backoff factor for retries in seconds.
Minimum is 1 and 0 will be silently converted to 1
Definition at line 64 of file Downloader.h.
bool startSession | ( | ) |
Start a new curl session if none is active at the moment.
Definition at line 161 of file Downloader.cc.
|
inline |
check the digest of a stream
input | stream to check, make sure the stream is in a valid state pointing to the correct position |
checksum | expected hash digest of the data |
Definition at line 82 of file Downloader.h.