Set User-Agent.

This commit is contained in:
tastytea 2020-01-06 15:33:48 +01:00
parent f195c5bcef
commit f01ec3eee0
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 13 additions and 2 deletions

View File

@ -4,7 +4,7 @@ find_package(CURL REQUIRED)
# Write version in header. # Write version in header.
configure_file ("version.hpp.in" configure_file ("version.hpp.in"
"${PROJECT_BINARY_DIR}/version.hpp" @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/version.hpp" @ONLY)
add_library(${PROJECT_NAME}) add_library(${PROJECT_NAME})
@ -19,7 +19,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PRIVATE PRIVATE
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>" # version.hpp "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" # version.hpp
PUBLIC PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

View File

@ -17,8 +17,10 @@
#include "curl_wrapper.hpp" #include "curl_wrapper.hpp"
#include "exceptions.hpp" #include "exceptions.hpp"
#include "log.hpp" #include "log.hpp"
#include "version.hpp"
#include <cstdint> #include <cstdint>
#include <cstring>
namespace mastodonpp namespace mastodonpp
{ {
@ -180,6 +182,15 @@ void CURLWrapper::setup_curl()
throw CURLException{code, "Failed to set write data", throw CURLException{code, "Failed to set write data",
_curl_buffer_error}; _curl_buffer_error};
} }
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
code = curl_easy_setopt(_connection, CURLOPT_USERAGENT,
string("mastorss/").append(version).c_str());
if (code != CURLE_OK)
{
throw CURLException{code, "Failed to set User-Agent",
_curl_buffer_error};
}
} }
} // namespace mastodonpp } // namespace mastodonpp