Added proxy to get_stream()

This commit is contained in:
tastytea 2018-05-26 23:48:03 +02:00
parent f019809133
commit b9603587c5
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
4 changed files with 45 additions and 32 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.15.0
VERSION 0.15.1
LANGUAGES CXX
)

View File

@ -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<curlopts::UserAgent>(parent.get_useragent());
if (!_proxy.empty())
{
request.setOpt<curlopts::Proxy>(_proxy);
if (!_proxy_userpw.empty())
string proxy;
string userpw;
parent.get_proxy(proxy, userpw);
if (!proxy.empty())
{
request.setOpt<curlopts::ProxyUserPwd>(_proxy_userpw);
request.setOpt<curlopts::Proxy>(proxy);
if (!userpw.empty())
{
request.setOpt<curlopts::ProxyUserPwd>(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;
}

View File

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

View File

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