From 17e8708bb4da0df3ccff68d08bdedd2d7c667720 Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Wed, 13 Feb 2019 16:05:24 -0800 Subject: [PATCH] Curl: Don't set curl fail on error when checking the connection When we are checking if the SSL is working and the server is up we don't care about the server return code. We just care if the server is responding. So we shouldn't set the curl option CURLOPT_FAILONERROR. The major problem of this change is that some servers don't respond to GET in '/'. So checking the connection using the version url will fail in that cases if CURLOPT_FAILONERROR is set. As we don't really need the other options, reverting that change back to how it was before. Fixes #792 Signed-off-by: Otavio Pontes --- src/curl.c | 16 +++++++++------- src/curl_async.c | 2 +- src/swupd_curl_internal.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/curl.c b/src/curl.c index 207a5347..2558542f 100644 --- a/src/curl.c +++ b/src/curl.c @@ -129,7 +129,7 @@ static int check_connection(const char *test_capath) long response = 0; debug("Curl - check_connection url: %s\n", version_url); - curl_ret = swupd_curl_set_basic_options(curl, version_url); + curl_ret = swupd_curl_set_basic_options(curl, version_url, false); if (curl_ret != CURLE_OK) { return -1; } @@ -522,7 +522,7 @@ restart_download: } } - curl_ret = swupd_curl_set_basic_options(curl, url); + curl_ret = swupd_curl_set_basic_options(curl, url, true); if (curl_ret != CURLE_OK) { goto exit; } @@ -704,7 +704,7 @@ exit: return curl_ret; } -CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url) +CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url, bool fail_on_error) { static bool use_ssl = true; @@ -749,10 +749,12 @@ CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url) goto exit; } - /* Avoid downloading HTML files for error responses if the HTTP code is >= 400 */ - curl_ret = curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); - if (curl_ret != CURLE_OK) { - goto exit; + if (fail_on_error) { + /* Avoid downloading HTML files for error responses if the HTTP code is >= 400 */ + curl_ret = curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); + if (curl_ret != CURLE_OK) { + goto exit; + } } exit: diff --git a/src/curl_async.c b/src/curl_async.c index f663f49c..76ef4ab7 100644 --- a/src/curl_async.c +++ b/src/curl_async.c @@ -439,7 +439,7 @@ static int process_download(struct swupd_curl_parallel_handle *h, struct multi_c goto out_bad; } - curl_ret = swupd_curl_set_basic_options(curl, file->url); + curl_ret = swupd_curl_set_basic_options(curl, file->url, true); if (curl_ret != CURLE_OK) { goto out_bad; } diff --git a/src/swupd_curl_internal.h b/src/swupd_curl_internal.h index ae8dae95..09d591e5 100644 --- a/src/swupd_curl_internal.h +++ b/src/swupd_curl_internal.h @@ -36,7 +36,7 @@ extern CURLcode swupd_download_file_close(CURLcode curl_ret, struct curl_file *f /* * Set swupd default basic options to curl handler. */ -extern CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url); +extern CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url, bool fail_on_error); /* Process download curl return code 'curl_ret' and if needed the response code to * fill 'err' with an error code and return the status of this download. */