From 75633bdb459338ea4669233f627c416ae4eed656 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 21 Nov 2020 22:15:32 +0100 Subject: [PATCH] Squashed 'src/curl_wrapper/' changes from f4ea01d..19a65d7 19a65d7 Add set_maxredirs(). git-subtree-dir: src/curl_wrapper git-subtree-split: 19a65d74745d72881b3b4c03b2dd84bd91c6c3d4 --- CMakeLists.txt | 2 +- src/curl_wrapper.cpp | 12 ++++++++++++ src/curl_wrapper.hpp | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a3b017..4d092d9 100644 --- a/CMakeLists.txt +++ b/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.cpp b/src/curl_wrapper.cpp index 7255854..8a58182 100644 --- a/src/curl_wrapper.cpp +++ b/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.hpp b/src/curl_wrapper.hpp index 62c6bfe..e980072 100644 --- a/src/curl_wrapper.hpp +++ b/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]{};