@@ -116,6 +116,17 @@ void Session::prepareHeader() {
116116 curl_->chunk = chunk;
117117}
118118
119+ void Session::prepareProxy () {
120+ const std::string protocol = url_.str ().substr (0 , url_.str ().find (' :' ));
121+ if (proxies_.has (protocol)) {
122+ curl_easy_setopt (curl_->handle , CURLOPT_PROXY, proxies_[protocol].c_str ());
123+ if (proxyAuth_.has (protocol)) {
124+ curl_easy_setopt (curl_->handle , CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsernameUnderlying (protocol).c_str ());
125+ curl_easy_setopt (curl_->handle , CURLOPT_PROXYPASSWORD, proxyAuth_.GetPasswordUnderlying (protocol).c_str ());
126+ }
127+ }
128+ }
129+
119130// Only supported with libcurl >= 7.61.0.
120131// As an alternative use SetHeader and add the token manually.
121132#if LIBCURL_VERSION_NUM >= 0x073D00
@@ -173,14 +184,8 @@ void Session::prepareCommonShared() {
173184 }
174185
175186 // Proxy:
176- const std::string protocol = url_.str ().substr (0 , url_.str ().find (' :' ));
177- if (proxies_.has (protocol)) {
178- curl_easy_setopt (curl_->handle , CURLOPT_PROXY, proxies_[protocol].c_str ());
179- if (proxyAuth_.has (protocol)) {
180- curl_easy_setopt (curl_->handle , CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsername (protocol));
181- curl_easy_setopt (curl_->handle , CURLOPT_PROXYPASSWORD, proxyAuth_.GetPassword (protocol));
182- }
183- }
187+ prepareProxy ();
188+
184189 // handle NO_PROXY override passed through Proxies object
185190 // Example: Proxies{"no_proxy": ""} will override environment variable definition with an empty list
186191 const std::array<std::string, 2 > no_proxy{" no_proxy" , " NO_PROXY" };
@@ -658,14 +663,7 @@ cpr_off_t Session::GetDownloadFileLength() {
658663 cpr_off_t downloadFileLength = -1 ;
659664 curl_easy_setopt (curl_->handle , CURLOPT_URL, url_.c_str ());
660665
661- const std::string protocol = url_.str ().substr (0 , url_.str ().find (' :' ));
662- if (proxies_.has (protocol)) {
663- curl_easy_setopt (curl_->handle , CURLOPT_PROXY, proxies_[protocol].c_str ());
664- if (proxyAuth_.has (protocol)) {
665- curl_easy_setopt (curl_->handle , CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsername (protocol));
666- curl_easy_setopt (curl_->handle , CURLOPT_PROXYPASSWORD, proxyAuth_.GetPassword (protocol));
667- }
668- }
666+ prepareProxy ();
669667
670668 curl_easy_setopt (curl_->handle , CURLOPT_HTTPGET, 1 );
671669 curl_easy_setopt (curl_->handle , CURLOPT_NOBODY, 1 );
0 commit comments