 |
Belle II Software
release-05-02-19
|
13 #include <framework/utilities/ScopeGuard.h>
18 namespace Belle2::Conditions {
23 class Downloader final {
48 return ScopeGuard([
this, started] {
if (started)
finishSession();});
77 bool download(
const std::string& url, std::ostream& stream,
bool silentOnMissing =
false);
88 std::string
joinWithSlash(
const std::string& base,
const std::string& second);
unsigned int getBackoffFactor() const
Get the backoff factor for retries in seconds.
void setMaxRetries(unsigned int retries)
Set the number of retries to perform when downloading fails with HTTP response code >=500,...
void finishSession()
Finish an existing curl session if any is active at the moment.
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
static std::string calculateChecksum(std::istream &input)
calculate the digest/checksum on a given string.
void setStalledTimeout(unsigned int timeout)
Set the timeout to wait for stalled connections (<10KB/s), 0 disables timeout.
ScopeGuard ensureSession()
Make sure there's an active session and return a ScopeGuard object that closes the session on destruc...
unsigned int m_stalledTimeout
Timeout to wait for stalled connections (<10KB/s)
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.
Downloader()=default
Create a new payload downloader.
unsigned int m_maxRetries
Number of retries to perform when downloading fails with HTTP response code >=500.
unsigned int m_connectionTimeout
Timeout to wait for connections in seconds.
static bool s_globalInit
flag to indicate whether curl has been initialized already
unsigned int getStalledTimeout() const
Get the timeout to wait for stalled connections (<10KB/s), 0 means no timeout.
bool startSession()
Start a new curl session if none is active at the moment.
static Downloader & getDefaultInstance()
Return the default instance.
unsigned int getMaxRetries() const
Get the number of retries to perform when downloading fails with HTTP response code >=500,...
void setConnectionTimeout(unsigned int timeout)
Set the timeout to wait for connections in seconds, 0 means built in curl default.
unsigned int getConnectionTimeout() const
Get the timeout to wait for connections in seconds, 0 means the built in curl default.
bool verifyChecksum(std::istream &input, const std::string &checksum)
check the digest of a stream
std::unique_ptr< CurlSession > m_session
curl session handle
void setBackoffFactor(unsigned int factor)
Set the backoff factor for retries in seconds.
unsigned int m_backoffFactor
Backoff factor for retries in seconds.