@@ -115,6 +115,17 @@ void Session::prepareHeader() {
115115 curl_->chunk = chunk;
116116}
117117
118+ void Session::prepareProxy () {
119+ const std::string protocol = url_.str ().substr (0 , url_.str ().find (' :' ));
120+ if (proxies_.has (protocol)) {
121+ curl_easy_setopt (curl_->handle , CURLOPT_PROXY, proxies_[protocol].c_str ());
122+ if (proxyAuth_.has (protocol)) {
123+ curl_easy_setopt (curl_->handle , CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsername (protocol));
124+ curl_easy_setopt (curl_->handle , CURLOPT_PROXYPASSWORD, proxyAuth_.GetPassword (protocol));
125+ }
126+ }
127+ }
128+
118129// Only supported with libcurl >= 7.61.0.
119130// As an alternative use SetHeader and add the token manually.
120131#if LIBCURL_VERSION_NUM >= 0x073D00
@@ -172,14 +183,7 @@ void Session::prepareCommonShared() {
172183 }
173184
174185 // Proxy:
175- const std::string protocol = url_.str ().substr (0 , url_.str ().find (' :' ));
176- if (proxies_.has (protocol)) {
177- curl_easy_setopt (curl_->handle , CURLOPT_PROXY, proxies_[protocol].c_str ());
178- if (proxyAuth_.has (protocol)) {
179- curl_easy_setopt (curl_->handle , CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsername (protocol));
180- curl_easy_setopt (curl_->handle , CURLOPT_PROXYPASSWORD, proxyAuth_.GetPassword (protocol));
181- }
182- }
186+ prepareProxy ();
183187
184188#if LIBCURL_VERSION_NUM >= 0x071506 // 7.21.6
185189 if (acceptEncoding_.empty ()) {
@@ -648,14 +652,7 @@ cpr_off_t Session::GetDownloadFileLength() {
648652 cpr_off_t downloadFileLength = -1 ;
649653 curl_easy_setopt (curl_->handle , CURLOPT_URL, url_.c_str ());
650654
651- const std::string protocol = url_.str ().substr (0 , url_.str ().find (' :' ));
652- if (proxies_.has (protocol)) {
653- curl_easy_setopt (curl_->handle , CURLOPT_PROXY, proxies_[protocol].c_str ());
654- if (proxyAuth_.has (protocol)) {
655- curl_easy_setopt (curl_->handle , CURLOPT_PROXYUSERNAME, proxyAuth_.GetUsername (protocol));
656- curl_easy_setopt (curl_->handle , CURLOPT_PROXYPASSWORD, proxyAuth_.GetPassword (protocol));
657- }
658- }
655+ prepareProxy ();
659656
660657 curl_easy_setopt (curl_->handle , CURLOPT_HTTPGET, 1 );
661658 curl_easy_setopt (curl_->handle , CURLOPT_NOBODY, 1 );
0 commit comments