Downloader: download file with cacert support

This commit is contained in:
halx99 2022-01-20 19:15:37 +08:00
parent 6d76dd9f6b
commit 1721141fd7
3 changed files with 23 additions and 8 deletions

View File

@ -563,8 +563,16 @@ private:
curl_easy_setopt(handle, CURLOPT_LOW_SPEED_LIMIT, 1L); curl_easy_setopt(handle, CURLOPT_LOW_SPEED_LIMIT, 1L);
curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, 10L); curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); if(task->cacertPath.empty())
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); {
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
}
else {
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 2L);
curl_easy_setopt(handle, CURLOPT_CAINFO, task->cacertPath.c_str());
}
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 5L); curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 5L);

View File

@ -50,13 +50,15 @@ DownloadTask::DownloadTask(std::string_view srcUrl,
std::string_view storagePath, std::string_view storagePath,
std::string_view checksum, std::string_view checksum,
std::string_view identifier, std::string_view identifier,
bool background) bool background,
std::string_view cacertPath)
{ {
this->requestURL = srcUrl; this->requestURL = srcUrl;
this->storagePath = storagePath; this->storagePath = storagePath;
this->checksum = checksum; this->checksum = checksum;
this->identifier = identifier; this->identifier = identifier;
this->background = background; this->background = background;
this->cacertPath = cacertPath;
} }
DownloadTask::~DownloadTask() DownloadTask::~DownloadTask()
@ -147,9 +149,10 @@ std::shared_ptr<DownloadTask> Downloader::createDownloadFileTask(std::string_vie
std::string_view storagePath, std::string_view storagePath,
std::string_view identifier, std::string_view identifier,
std::string_view md5checksum, std::string_view md5checksum,
bool background) bool background,
std::string_view cacertPath)
{ {
auto task = std::make_shared<DownloadTask>(srcUrl, storagePath, md5checksum, identifier, background); auto task = std::make_shared<DownloadTask>(srcUrl, storagePath, md5checksum, identifier, background, cacertPath);
do do
{ {
if (srcUrl.empty() || storagePath.empty()) if (srcUrl.empty() || storagePath.empty())

View File

@ -61,6 +61,8 @@ public:
std::string requestURL; std::string requestURL;
std::string storagePath; std::string storagePath;
std::string cacertPath;
struct struct
{ {
// progress // progress
@ -77,7 +79,8 @@ public:
std::string_view storagePath, std::string_view storagePath,
std::string_view checksum, // currently is MD5 std::string_view checksum, // currently is MD5
std::string_view identifier, std::string_view identifier,
bool background); bool background,
std::string_view cacertPath);
virtual ~DownloadTask(); virtual ~DownloadTask();
@ -140,7 +143,8 @@ public:
std::string_view storagePath, std::string_view storagePath,
std::string_view identifier = "", std::string_view identifier = "",
std::string_view checksum = "", std::string_view checksum = "",
bool background = false); bool background = false,
std::string_view cacertPath = "");
private: private:
std::unique_ptr<IDownloaderImpl> _impl; std::unique_ptr<IDownloaderImpl> _impl;