Add set_maxredirs().
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2020-11-21 22:13:57 +01:00
parent f4ea01d96e
commit 19a65d7474
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 29 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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]{};