diff --git a/include/connection.hpp b/include/connection.hpp index e2735b8..b32acea 100644 --- a/include/connection.hpp +++ b/include/connection.hpp @@ -99,13 +99,6 @@ public: return get(endpoint, {}); } - /*! @copydoc CURLWrapper::set_proxy(string_view) - * - * Sets also the proxy for the Instance you used to initialize this - * Connection. - */ - void set_proxy(string_view proxy); - /*! * @brief Copy new stream contents and delete the “original”. * diff --git a/include/instance.hpp b/include/instance.hpp index 28f8f27..5af177c 100644 --- a/include/instance.hpp +++ b/include/instance.hpp @@ -95,11 +95,35 @@ public: [[nodiscard]] uint64_t get_max_chars(); + /*! @copydoc CURLWrapper::set_proxy(string_view) + * + * Sets also the proxy for all Connection%s that are initialized with this + * Instance afterwards. + */ + void set_proxy(const string_view proxy) + { + _proxy = proxy; + CURLWrapper::set_proxy(proxy); + } + + /*! + * @brief Returns the proxy string that was previously set. + * + * Does not return the proxy if it was set from an environment variable. + * + * @since 0.1.0 + */ + string_view get_proxy() const + { + return _proxy; + } + private: const string _hostname; const string _baseuri; string _access_token; uint64_t _max_chars; + string _proxy; }; } // namespace mastodonpp diff --git a/src/connection.cpp b/src/connection.cpp index 3aaa236..0deaed8 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -24,7 +24,13 @@ using std::holds_alternative; Connection::Connection(Instance &instance) : _instance{instance} , _baseuri{instance.get_baseuri()} -{} +{ + auto proxy{_instance.get_proxy()}; + if (!proxy.empty()) + { + CURLWrapper::set_proxy(proxy); + } +} answer_type Connection::get(const endpoint_variant &endpoint, const parametermap ¶meters) @@ -42,12 +48,6 @@ answer_type Connection::get(const endpoint_variant &endpoint, return make_request(http_method::GET, uri, parameters); } -void Connection::set_proxy(const string_view proxy) -{ - CURLWrapper::set_proxy(proxy); - _instance.set_proxy(proxy); -} - string Connection::get_new_stream_contents() { buffer_mutex.lock();