summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-10-10 16:13:14 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-10-17 10:27:43 +0200
commita62f63f08f57530098465bd1655fe93937a14cf0 (patch)
treed916c7203022c599171779718ae86825a3d21fd5 /src
parent15e6dcc0996234429f59c2c1d9dd314c3715a265 (diff)
downloadjustbuild-a62f63f08f57530098465bd1655fe93937a14cf0.tar.gz
curl_easy_handle: Ensure we report a fail on HTTP codes >=400
...which signal either cient- or server-side failures. This ensures we exit with a failed network fetch early in cases where it is clear we won't receive useful data. (cherry-picked from 4ef74caa5d96471d058bd1c9542d79ad58538da7)
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/utils/curl_easy_handle.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/other_tools/utils/curl_easy_handle.cpp b/src/other_tools/utils/curl_easy_handle.cpp
index 17ba0261..6a98056e 100644
--- a/src/other_tools/utils/curl_easy_handle.cpp
+++ b/src/other_tools/utils/curl_easy_handle.cpp
@@ -116,6 +116,10 @@ auto CurlEasyHandle::DownloadToFile(
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-vararg)
curl_easy_setopt(handle_.get(), CURLOPT_FOLLOWLOCATION, 1);
+ // ensure failure on error codes that otherwise might return OK
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-vararg)
+ curl_easy_setopt(handle_.get(), CURLOPT_FAILONERROR, 1);
+
// set callback for writing to file
std::ofstream file(file_path.c_str(), std::ios::binary);
@@ -194,6 +198,10 @@ auto CurlEasyHandle::DownloadToString(std::string const& url) noexcept
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-vararg)
curl_easy_setopt(handle_.get(), CURLOPT_FOLLOWLOCATION, 1);
+ // ensure failure on error codes that otherwise might return OK
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg, hicpp-vararg)
+ curl_easy_setopt(handle_.get(), CURLOPT_FAILONERROR, 1);
+
// set callback for writing to string
std::string content{};