From a62f63f08f57530098465bd1655fe93937a14cf0 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 10 Oct 2023 16:13:14 +0200 Subject: 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) --- src/other_tools/utils/curl_easy_handle.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/other_tools/utils/curl_easy_handle.cpp') 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{}; -- cgit v1.2.3