@@ -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,46 @@ 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 proxy_username = configuration->proxy_username ;
419+ auto proxy_password = configuration->proxy_password ;
420+
421+ CTL_ERR (" === Proxy configuration ===" );
422+ CTL_ERR (" Proxy url: " << proxy_url);
423+ CTL_ERR (" Verify proxy ssl: " << verify_proxy_ssl);
424+
425+ curl_easy_setopt (handle, CURLOPT_PROXY, proxy_url.c_str ());
426+ curl_easy_setopt (handle, CURLOPT_SSL_VERIFYPEER, 0L );
427+ curl_easy_setopt (handle, CURLOPT_SSL_VERIFYHOST, 0L );
428+ // todo: allow this later on
429+ curl_easy_setopt (handle, CURLOPT_PROXY_SSL_VERIFYPEER, 0L );
430+ curl_easy_setopt (handle, CURLOPT_PROXY_SSL_VERIFYHOST, 0L );
431+
432+ if (!proxy_username.empty ()) {
433+ std::string proxy_auth = proxy_username + " :" + proxy_password;
434+ CTL_ERR (" Proxy auth: " << proxy_auth);
435+ curl_easy_setopt (handle, CURLOPT_PROXYUSERPWD, proxy_auth.c_str ());
436+ }
437+
438+ curl_easy_setopt (handle, CURLOPT_NOPROXY,
439+ configuration->no_proxy .c_str ());
440+ }
441+ } else {
442+ CTL_ERR (" Failed to get configuration" );
443+ }
444+
410445 curl_easy_setopt (handle, CURLOPT_URL, item.downloadUrl .c_str ());
411446 curl_easy_setopt (handle, CURLOPT_WRITEFUNCTION, WriteCallback);
412447 curl_easy_setopt (handle, CURLOPT_WRITEDATA, file);
413448 curl_easy_setopt (handle, CURLOPT_FOLLOWLOCATION, 1L );
414449 curl_easy_setopt (handle, CURLOPT_NOPROGRESS, 0L );
415450 curl_easy_setopt (handle, CURLOPT_XFERINFOFUNCTION, ProgressCallback);
416451 curl_easy_setopt (handle, CURLOPT_XFERINFODATA, dl_data);
452+ curl_easy_setopt (handle, CURLOPT_VERBOSE, 1L );
417453
418454 auto headers = curl_utils::GetHeaders (item.downloadUrl );
419455 if (headers) {
0 commit comments