diff --git a/CMakeLists.txt b/CMakeLists.txt index c768530..812afc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (mastodon-cpp - VERSION 0.15.0 + VERSION 0.15.1 LANGUAGES CXX ) diff --git a/src/http.cpp b/src/http.cpp index 5f3c489..f11bb2b 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -35,8 +35,6 @@ API::http::http(const API &api, const string &instance, , _instance(instance) , _access_token(access_token) , _cancel_stream(false) -, _proxy("") -, _proxy_userpw("") { curlpp::initialize(); } @@ -72,12 +70,17 @@ const uint_fast16_t API::http::request(const method &meth, ttdebug << "User-Agent: " << parent.get_useragent() << "\n"; request.setOpt(parent.get_useragent()); - if (!_proxy.empty()) { - request.setOpt(_proxy); - if (!_proxy_userpw.empty()) + string proxy; + string userpw; + parent.get_proxy(proxy, userpw); + if (!proxy.empty()) { - request.setOpt(_proxy_userpw); + request.setOpt(proxy); + if (!userpw.empty()) + { + request.setOpt(userpw); + } } } @@ -228,9 +231,3 @@ std::mutex &API::http::get_mutex() { return _mutex; } - -const void API::http::set_proxy(const string &proxy, const string &userpw) -{ - _proxy = proxy; - _proxy_userpw = userpw; -} diff --git a/src/mastodon-cpp.cpp b/src/mastodon-cpp.cpp index 5843e66..8d52eeb 100644 --- a/src/mastodon-cpp.cpp +++ b/src/mastodon-cpp.cpp @@ -33,6 +33,8 @@ API::API(const string &instance, const string &access_token) , _useragent(string("mastodon-cpp/") + global::version) , _http(*this, instance, access_token) , _exceptions(false) +, _proxy("") +, _proxy_userpw("") { // } @@ -574,5 +576,18 @@ const string API::unescape_html(const string &html) const void API::set_proxy(const string &proxy, const string &userpw) { - _http.set_proxy(proxy, userpw); + _proxy = proxy; + _proxy_userpw = userpw; +} + +const void API::get_proxy(string &proxy, string &userpw) const +{ + if (!_proxy.empty()) + { + proxy = _proxy; + if (!_proxy_userpw.empty()) + { + userpw = _proxy_userpw; + } + } } diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index da39e90..b9f1b1c 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -146,21 +146,6 @@ public: */ std::mutex &get_mutex(); - /*! - * @brief Sets the proxy. - * - * Since mastodon-cpp is built on libcurl, it respects the same - * proxy environment variables. See `man curl`. - * - * @param proxy See `man 3 CURLOPT_PROXY` - * @param userpw See `man 3 CURLOPT_PROXYUSERPWD` (optional) - * - * @since 0.15.0 - * - * @return { description_of_the_return_value } - */ - const void set_proxy(const string &proxy, const string &userpw = ""); - private: const API &parent; const string _instance; @@ -168,8 +153,6 @@ public: string _headers; bool _cancel_stream; std::mutex _mutex; - string _proxy; - string _proxy_userpw; const size_t callback_write(char* data, size_t size, size_t nmemb, string *oss); @@ -413,12 +396,28 @@ public: static const string unescape_html(const string &html); /*! - * @brief Calls Mastodon::API::http::set_proxy() + * @brief Sets the proxy. + * + * Since mastodon-cpp is built on libcurl, it respects the same + * proxy environment variables. See `man curl`. + * + * @param proxy See `man 3 CURLOPT_PROXY` + * @param userpw See `man 3 CURLOPT_PROXYUSERPWD` (optional) * * @since 0.15.0 */ const void set_proxy(const string &proxy, const string &userpw = ""); + /*! + * @brief For internal use + * + * @param proxy URL + * @param userpw username:password + * + * @since 0.15.1 + */ + const void get_proxy(string &proxy, string &userpw) const; + /*! * @brief Make a GET request which doesn't require parameters. * @@ -683,6 +682,8 @@ private: string _useragent; http _http; bool _exceptions; + string _proxy; + string _proxy_userpw; /*! * @brief Converts map of parameters into a string.