Skip to content

Commit 0e303d9

Browse files
committed
update_engine: Stop using deprecated curl options and info names
The CURLOPT_PROTOCOLS, CURLOPT_REDIR_PROTOCOLS options and the CURLINFO_CONTENT_LENGTH_DOWNLOAD info name are deprecated, but fortunately they have straightforward replacements. Since we are running CI for update_engine on Ubuntu 22.04, which has curl 7.81, we need to use some ifdeffery for CURLOPT_PROTOCOLS_STR and CURLOPT_REDIR_PROTOCOLS_STR as these have been introduced in 7.85. On Flatcar we have 7.87, so we will use the other branch of the ifdefs. Such tricks were not needed for CURLINFO_CONTENT_LENGTH_DOWNLOAD as it was deprecated since 7.55, so even the Ubuntu LTS has a newer version of curl than that.
1 parent 12d43a8 commit 0e303d9

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/update_engine/libcurl_http_fetcher.cc

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,19 @@ void LibcurlHttpFetcher::SetCurlOptionsForHttp() {
152152
if (!auth_user_.empty()) {
153153
LOG(INFO) << "(This is not HTTPS, ignoring HTTP Auth credentials)";
154154
}
155+
#if (LIBCURL_VERSION_MAJOR > 7) || ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR >= 85))
156+
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_PROTOCOLS_STR, "http"),
157+
CURLE_OK);
158+
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_REDIR_PROTOCOLS_STR,
159+
"http"),
160+
CURLE_OK);
161+
#else
155162
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_PROTOCOLS, CURLPROTO_HTTP),
156163
CURLE_OK);
157164
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_REDIR_PROTOCOLS,
158165
CURLPROTO_HTTP),
159166
CURLE_OK);
167+
#endif
160168
}
161169

162170
// Security lock-down in official builds: makes sure that peer certificate
@@ -168,11 +176,19 @@ void LibcurlHttpFetcher::SetCurlOptionsForHttps() {
168176
CURLE_OK);
169177
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_CAPATH, kCACertificatesPath),
170178
CURLE_OK);
179+
#if (LIBCURL_VERSION_MAJOR > 7) || ((LIBCURL_VERSION_MAJOR == 7) && (LIBCURL_VERSION_MINOR >= 85))
180+
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_PROTOCOLS_STR, "https"),
181+
CURLE_OK);
182+
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_REDIR_PROTOCOLS_STR,
183+
"https"),
184+
CURLE_OK);
185+
#else
171186
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS),
172187
CURLE_OK);
173188
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_REDIR_PROTOCOLS,
174189
CURLPROTO_HTTPS),
175190
CURLE_OK);
191+
#endif
176192
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_SSL_CIPHER_LIST, "HIGH:!ADH"),
177193
CURLE_OK);
178194
CHECK_EQ(curl_easy_setopt(curl_handle_, CURLOPT_SSLVERSION,
@@ -328,13 +344,12 @@ size_t LibcurlHttpFetcher::LibcurlWrite(void *ptr, size_t size, size_t nmemb) {
328344

329345
sent_byte_ = true;
330346
{
331-
double transfer_size_double;
347+
curl_off_t download_transfer_size;
332348
CHECK_EQ(curl_easy_getinfo(curl_handle_,
333-
CURLINFO_CONTENT_LENGTH_DOWNLOAD,
334-
&transfer_size_double), CURLE_OK);
335-
off_t new_transfer_size = static_cast<off_t>(transfer_size_double);
336-
if (new_transfer_size > 0) {
337-
transfer_size_ = resume_offset_ + new_transfer_size;
349+
CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
350+
&download_transfer_size), CURLE_OK);
351+
if (download_transfer_size > 0) {
352+
transfer_size_ = resume_offset_ + download_transfer_size;
338353
}
339354
}
340355
bytes_downloaded_ += payload_size;

0 commit comments

Comments
 (0)