Add set_proxy().
This commit is contained in:
parent
1f78b00205
commit
deed340f3d
|
@ -98,6 +98,13 @@ 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(const string_view proxy);
|
||||
|
||||
private:
|
||||
Instance &_instance;
|
||||
const string_view _baseuri;
|
||||
|
|
|
@ -127,6 +127,18 @@ public:
|
|||
return _connection;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set the proxy to use.
|
||||
*
|
||||
* See [CURLOPT_PROXY(3)]
|
||||
* (https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html).
|
||||
*
|
||||
* @param proxy Examples: "socks4a://127.0.0.1:9050", "http://[::1]:3128".
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
void set_proxy(const string_view proxy);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* @brief Make a HTTP request.
|
||||
|
|
|
@ -42,4 +42,10 @@ 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);
|
||||
}
|
||||
|
||||
} // namespace mastodonpp
|
||||
|
|
|
@ -63,6 +63,16 @@ CURLWrapper::~CURLWrapper() noexcept
|
|||
}
|
||||
}
|
||||
|
||||
void CURLWrapper::set_proxy(const string_view proxy)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
CURLcode code = curl_easy_setopt(_connection, CURLOPT_PROXY, proxy);
|
||||
if (code != CURLE_OK)
|
||||
{
|
||||
throw CURLException{code, "Failed to set proxy", _curl_buffer_error};
|
||||
}
|
||||
}
|
||||
|
||||
answer_type CURLWrapper::make_request(const http_method &method, string uri,
|
||||
const parametermap ¶meters)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user