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

@ -562,9 +562,17 @@ private:
curl_easy_setopt(handle, CURLOPT_LOW_SPEED_LIMIT, 1L);
curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, 10L);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
if(task->cacertPath.empty())
{
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_MAXREDIRS, 5L);

View File

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

View File

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