diff options
author | tastytea | 2020-01-12 17:35:11 +0100 |
---|---|---|
committer | tastytea | 2020-01-12 17:37:06 +0100 |
commit | 1b4ad05acb1c3605c3a6949a746228d31da5e9da (patch) | |
tree | 7214424f198be77b741eb79d0b61ceed8ce6c5b1 /src | |
parent | 04526f37cc83bf13b1ba0715ede6826b3b053720 (diff) | |
download | mastodonpp-1b4ad05acb1c3605c3a6949a746228d31da5e9da.tar mastodonpp-1b4ad05acb1c3605c3a6949a746228d31da5e9da.tar.gz mastodonpp-1b4ad05acb1c3605c3a6949a746228d31da5e9da.zip |
Add set_useragent().
Diffstat (limited to 'src')
-rw-r--r-- | src/curl_wrapper.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index d5d96be..0fb0540 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -187,9 +187,10 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri, return answer; } -void CURLWrapper::setup_connection_properties(string_view proxy, - string_view access_token, - string_view cainfo) +void CURLWrapper::setup_connection_properties(const string_view proxy, + const string_view access_token, + const string_view cainfo, + const string_view useragent) { if (!proxy.empty()) { @@ -205,6 +206,11 @@ void CURLWrapper::setup_connection_properties(string_view proxy, { set_cainfo(cainfo); } + + if (!useragent.empty()) + { + set_useragent(useragent); + } } void CURLWrapper::set_proxy(const string_view proxy) @@ -252,6 +258,19 @@ void CURLWrapper::set_cainfo(const string_view path) } } +void CURLWrapper::set_useragent(const string_view useragent) +{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + CURLcode code{curl_easy_setopt(_connection, CURLOPT_USERAGENT, + useragent.data())}; + if (code != CURLE_OK) + { + throw CURLException{code, "Failed to set User-Agent", + _curl_buffer_error}; + } + debuglog << "Set User-Agent to: " << useragent << '\n'; +} + size_t CURLWrapper::writer_body(char *data, size_t size, size_t nmemb) { if(data == nullptr) @@ -316,18 +335,11 @@ void CURLWrapper::setup_curl() // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) curl_easy_setopt(_connection, CURLOPT_NOPROGRESS, 0L); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - CURLcode code{curl_easy_setopt(_connection, CURLOPT_USERAGENT, - (string("mastodonpp/") += version).c_str())}; - if (code != CURLE_OK) - { - throw CURLException{code, "Failed to set User-Agent", - _curl_buffer_error}; - } + set_useragent((string("mastodonpp/") += version)); // The next 2 only fail if HTTP is not supported. // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) - code = curl_easy_setopt(_connection, CURLOPT_FOLLOWLOCATION, 1L); + CURLcode code{curl_easy_setopt(_connection, CURLOPT_FOLLOWLOCATION, 1L)}; if (code != CURLE_OK) { throw CURLException{code, "HTTP is not supported.", _curl_buffer_error}; |