@@ -52,6 +52,48 @@ cpp::result<void, std::string> ProcessCompletedTransfers(CURLM* multi_handle) {
5252 }
5353 return {};
5454}
55+
56+ void SetUpProxy (CURL* handle, std::shared_ptr<ConfigService> config_service) {
57+ auto configuration = config_service->GetApiServerConfiguration ();
58+ if (configuration.has_value ()) {
59+ if (!configuration->proxy_url .empty ()) {
60+ auto proxy_url = configuration->proxy_url ;
61+ auto verify_proxy_ssl = configuration->verify_proxy_ssl ;
62+ auto verify_proxy_host_ssl = configuration->verify_proxy_host_ssl ;
63+
64+ auto verify_ssl = configuration->verify_peer_ssl ;
65+ auto verify_host_ssl = configuration->verify_host_ssl ;
66+
67+ auto proxy_username = configuration->proxy_username ;
68+ auto proxy_password = configuration->proxy_password ;
69+
70+ CTL_INF (" === Proxy configuration ===" );
71+ CTL_INF (" Proxy url: " << proxy_url);
72+ CTL_INF (" Verify proxy ssl: " << verify_proxy_ssl);
73+ CTL_INF (" Verify proxy host ssl: " << verify_proxy_host_ssl);
74+ CTL_INF (" Verify ssl: " << verify_ssl);
75+ CTL_INF (" Verify host ssl: " << verify_host_ssl);
76+
77+ curl_easy_setopt (handle, CURLOPT_PROXY, proxy_url.c_str ());
78+ curl_easy_setopt (handle, CURLOPT_SSL_VERIFYPEER, verify_ssl ? 1L : 0L );
79+ curl_easy_setopt (handle, CURLOPT_SSL_VERIFYHOST,
80+ verify_host_ssl ? 2L : 0L );
81+
82+ curl_easy_setopt (handle, CURLOPT_PROXY_SSL_VERIFYPEER,
83+ verify_proxy_ssl ? 1L : 0L );
84+ curl_easy_setopt (handle, CURLOPT_PROXY_SSL_VERIFYHOST,
85+ verify_proxy_host_ssl ? 2L : 0L );
86+
87+ auto proxy_auth = proxy_username + " :" + proxy_password;
88+ curl_easy_setopt (handle, CURLOPT_PROXYUSERPWD, proxy_auth.c_str ());
89+
90+ curl_easy_setopt (handle, CURLOPT_NOPROXY,
91+ configuration->no_proxy .c_str ());
92+ }
93+ } else {
94+ CTL_ERR (" Failed to get configuration" );
95+ }
96+ }
5597} // namespace
5698
5799cpp::result<bool , std::string> DownloadService::AddDownloadTask (
@@ -87,7 +129,7 @@ cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
87129 return cpp::fail (static_cast <std::string>(" Failed to init CURL" ));
88130 }
89131
90- // TODO: namh add header here
132+ SetUpProxy (curl, config_service_);
91133 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L );
92134 curl_easy_setopt (curl, CURLOPT_NOBODY, 1L );
93135 curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
@@ -190,7 +232,8 @@ cpp::result<bool, std::string> DownloadService::Download(
190232
191233 curl_easy_setopt (curl, CURLOPT_HTTPHEADER, curl_headers);
192234 }
193- // TODO: namh add proxy setting here
235+
236+ SetUpProxy (curl, config_service_);
194237 curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &WriteCallback);
195238 curl_easy_setopt (curl, CURLOPT_WRITEDATA, file);
196239 curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0L );
@@ -339,7 +382,6 @@ void DownloadService::ProcessTask(DownloadTask& task, int worker_id) {
339382 });
340383 worker_data->downloading_data_map [item.id ] = dl_data_ptr;
341384
342- CTL_ERR (" Namh Setup curl" );
343385 SetUpCurlHandle (handle, item, file, dl_data_ptr.get ());
344386 curl_multi_add_handle (worker_data->multi_handle , handle);
345387 task_handles.push_back (std::make_pair (handle, file));
@@ -410,57 +452,14 @@ cpp::result<void, ProcessDownloadFailed> DownloadService::ProcessMultiDownload(
410452
411453void DownloadService::SetUpCurlHandle (CURL* handle, const DownloadItem& item,
412454 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-
455+ SetUpProxy (handle, config_service_);
456456 curl_easy_setopt (handle, CURLOPT_URL, item.downloadUrl .c_str ());
457457 curl_easy_setopt (handle, CURLOPT_WRITEFUNCTION, WriteCallback);
458458 curl_easy_setopt (handle, CURLOPT_WRITEDATA, file);
459459 curl_easy_setopt (handle, CURLOPT_FOLLOWLOCATION, 1L );
460460 curl_easy_setopt (handle, CURLOPT_NOPROGRESS, 0L );
461461 curl_easy_setopt (handle, CURLOPT_XFERINFOFUNCTION, ProgressCallback);
462462 curl_easy_setopt (handle, CURLOPT_XFERINFODATA, dl_data);
463- curl_easy_setopt (handle, CURLOPT_VERBOSE, 1L );
464463
465464 auto headers = curl_utils::GetHeaders (item.downloadUrl );
466465 if (headers) {
0 commit comments