diff --git a/src/curl_wrapper/CMakeLists.txt b/src/curl_wrapper/CMakeLists.txt index 5a3b017..4d092d9 100644 --- a/src/curl_wrapper/CMakeLists.txt +++ b/src/curl_wrapper/CMakeLists.txt @@ -6,7 +6,7 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12) endif() project(curl_wrapper - VERSION 0.1.1 + VERSION 0.1.2 DESCRIPTION "Light libcurl wrapper." LANGUAGES CXX) diff --git a/src/curl_wrapper/src/curl_wrapper.cpp b/src/curl_wrapper/src/curl_wrapper.cpp index 7255854..8a58182 100644 --- a/src/curl_wrapper/src/curl_wrapper.cpp +++ b/src/curl_wrapper/src/curl_wrapper.cpp @@ -190,6 +190,18 @@ answer CURLWrapper::make_http_request(http_method method, string_view uri) _buffer_body}; } +void CURLWrapper::set_maxredirs(long redirections) // NOLINT(google-runtime-int) +{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + curl_easy_setopt(_connection, CURLOPT_MAXREDIRS, redirections); + + if (redirections == 0) + { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + check(curl_easy_setopt(_connection, CURLOPT_FOLLOWLOCATION, 0L)); + } +} + size_t CURLWrapper::writer_body(char *data, size_t size, size_t nmemb) { if (data == nullptr) diff --git a/src/curl_wrapper/src/curl_wrapper.hpp b/src/curl_wrapper/src/curl_wrapper.hpp index 62c6bfe..e980072 100644 --- a/src/curl_wrapper/src/curl_wrapper.hpp +++ b/src/curl_wrapper/src/curl_wrapper.hpp @@ -154,6 +154,22 @@ public: */ [[nodiscard]] answer make_http_request(http_method method, string_view uri); + /*! + * @brief Set maximum redirections to follow. + * + * For more information consult [CURLOPT_MAXREDIRS(3)] + * (https://curl.haxx.se/libcurl/c/CURLOPT_MAXREDIRS.html) and + * [CURLOPT_FOLLOWLOCATION(3)] + * (https://curl.haxx.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html). + * + * @param redirections Number of allowed redirections. If set to 0, + * CURLOPT_FOLLOWLOCATION is set to 0L. Set it to -1 + * for an infinite number of redirects. + * + * @since 0.1.2 + */ + void set_maxredirs(long redirections); // NOLINT(google-runtime-int) + private: CURL *_connection{}; char _buffer_error[CURL_ERROR_SIZE]{};