Squashed 'src/curl_wrapper/' changes from f4ea01d..19a65d7
19a65d7 Add set_maxredirs(). git-subtree-dir: src/curl_wrapper git-subtree-split: 19a65d74745d72881b3b4c03b2dd84bd91c6c3d4
This commit is contained in:
parent
1d4139cf0e
commit
75633bdb45
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]{};
|
||||
|
|
Loading…
Reference in New Issue
Block a user