Move set_proxy() to Instance.

This commit is contained in:
tastytea 2020-01-09 11:23:15 +01:00
parent 8482f51aff
commit e4a5b8e9ce
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
3 changed files with 31 additions and 14 deletions

View File

@ -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.
*

View File

@ -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

View File

@ -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 &parameters)
@ -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();