@@ -87,6 +87,7 @@ cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
8787 return cpp::fail (static_cast <std::string>(" Failed to init CURL" ));
8888 }
8989
90+ // TODO: namh add header here
9091 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L );
9192 curl_easy_setopt (curl, CURLOPT_NOBODY, 1L );
9293 curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
@@ -189,6 +190,7 @@ cpp::result<bool, std::string> DownloadService::Download(
189190
190191 curl_easy_setopt (curl, CURLOPT_HTTPHEADER, curl_headers);
191192 }
193+ // TODO: namh add proxy setting here
192194 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
193195 curl_easy_setopt (curl, CURLOPT_WRITEDATA, file);
194196 curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0L );
@@ -337,6 +339,7 @@ void DownloadService::ProcessTask(DownloadTask& task, int worker_id) {
337339 });
338340 worker_data->downloading_data_map [item.id ] = dl_data_ptr;
339341
342+ CTL_ERR (" Namh Setup curl" );
340343 SetUpCurlHandle (handle, item, file, dl_data_ptr.get ());
341344 curl_multi_add_handle (worker_data->multi_handle , handle);
342345 task_handles.push_back (std::make_pair (handle, file));
@@ -407,13 +410,57 @@ cpp::result<void, ProcessDownloadFailed> DownloadService::ProcessMultiDownload(
407410
408411void DownloadService::SetUpCurlHandle (CURL* handle, const DownloadItem& item,
409412 FILE* file, DownloadingData* dl_data) {
413+ auto configuration = config_service_->GetApiServerConfiguration ();
414+ if (configuration.has_value ()) {
415+ if (!configuration->proxy_url .empty ()) {
416+ auto proxy_url = configuration->proxy_url ;
417+ auto verify_proxy_ssl = configuration->verify_proxy_ssl ;
418+ auto verify_proxy_host_ssl = configuration->verify_proxy_host_ssl ;
419+
420+ auto verify_ssl = configuration->verify_peer_ssl ;
421+ auto verify_host_ssl = configuration->verify_host_ssl ;
422+
423+ auto proxy_username = configuration->proxy_username ;
424+ auto proxy_password = configuration->proxy_password ;
425+
426+ CTL_ERR (" === Proxy configuration ===" );
427+ CTL_ERR (" Proxy url: " << proxy_url);
428+ CTL_ERR (" Verify proxy ssl: " << verify_proxy_ssl);
429+ CTL_ERR (" Verify proxy host ssl: " << verify_proxy_host_ssl);
430+ CTL_ERR (" Verify ssl: " << verify_ssl);
431+ CTL_ERR (" Verify host ssl: " << verify_host_ssl);
432+
433+ curl_easy_setopt (handle, CURLOPT_PROXY, proxy_url.c_str ());
434+ curl_easy_setopt (handle, CURLOPT_SSL_VERIFYPEER, verify_ssl ? 1L : 0L );
435+ curl_easy_setopt (handle, CURLOPT_SSL_VERIFYHOST,
436+ verify_host_ssl ? 2L : 0L );
437+
438+ curl_easy_setopt (handle, CURLOPT_PROXY_SSL_VERIFYPEER,
439+ verify_proxy_ssl ? 1L : 0L );
440+ curl_easy_setopt (handle, CURLOPT_PROXY_SSL_VERIFYHOST,
441+ verify_proxy_host_ssl ? 2L : 0L );
442+
443+ if (!proxy_username.empty ()) {
444+ std::string proxy_auth = proxy_username + " :" + proxy_password;
445+ CTL_ERR (" Proxy auth: " << proxy_auth);
446+ curl_easy_setopt (handle, CURLOPT_PROXYUSERPWD, proxy_auth.c_str ());
447+ }
448+
449+ curl_easy_setopt (handle, CURLOPT_NOPROXY,
450+ configuration->no_proxy .c_str ());
451+ }
452+ } else {
453+ CTL_ERR (" Failed to get configuration" );
454+ }
455+
410456 curl_easy_setopt (handle, CURLOPT_URL, item.downloadUrl .c_str ());
411457 curl_easy_setopt (handle, CURLOPT_WRITEFUNCTION, WriteCallback);
412458 curl_easy_setopt (handle, CURLOPT_WRITEDATA, file);
413459 curl_easy_setopt (handle, CURLOPT_FOLLOWLOCATION, 1L );
414460 curl_easy_setopt (handle, CURLOPT_NOPROGRESS, 0L );
415461 curl_easy_setopt (handle, CURLOPT_XFERINFOFUNCTION, ProgressCallback);
416462 curl_easy_setopt (handle, CURLOPT_XFERINFODATA, dl_data);
463+ curl_easy_setopt (handle, CURLOPT_VERBOSE, 1L );
417464
418465 auto headers = curl_utils::GetHeaders (item.downloadUrl );
419466 if (headers) {
0 commit comments