Add set_proxy().

This commit is contained in:
tastytea 2020-01-08 17:16:15 +01:00
parent 1f78b00205
commit deed340f3d
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 35 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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