Moved set_proxy() to API::http().
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
API::set_proxy() calls API::http::set_proxy(). Deleted API::get_proxy().
This commit is contained in:
parent
acbcb6224e
commit
d2a4d835de
59
src/http.cpp
59
src/http.cpp
|
@ -59,19 +59,29 @@ API::http::http(const API &api, const string &instance,
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HTTPSClientSession::ProxyConfig proxyconfig;
|
|
||||||
string env_proxy = Environment::get("http_proxy");
|
string env_proxy = Environment::get("http_proxy");
|
||||||
regex re_proxy("^(?:https?://)?(?:([^:]+):?([^@]*)@)?" // user:password
|
size_t pos;
|
||||||
"([^:]+):([[:digit:]]+/?)"); // host:port
|
|
||||||
smatch match;
|
|
||||||
|
|
||||||
regex_search(env_proxy, match, re_proxy);
|
// Only keep text between // and /.
|
||||||
proxyconfig.host = match[3].str();
|
if ((pos = env_proxy.find("//")) != string::npos)
|
||||||
proxyconfig.port = std::stoi(match[4].str());
|
{
|
||||||
proxyconfig.username = match[1].str();
|
env_proxy = env_proxy.substr(pos + 2);
|
||||||
proxyconfig.password = match[2].str();
|
}
|
||||||
|
if ((pos = env_proxy.find('/')) != string::npos)
|
||||||
|
{
|
||||||
|
env_proxy = env_proxy.substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
HTTPSClientSession::setGlobalProxyConfig(proxyconfig);
|
if ((pos = env_proxy.find('@')) != string::npos)
|
||||||
|
{
|
||||||
|
string hostport = env_proxy.substr(pos + 1);
|
||||||
|
string userpw = env_proxy.substr(0, pos);
|
||||||
|
parent.set_proxy(hostport, userpw);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parent.set_proxy(env_proxy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception &)
|
catch (const std::exception &)
|
||||||
{
|
{
|
||||||
|
@ -85,35 +95,28 @@ API::http::~http()
|
||||||
Poco::Net::uninitializeSSL();
|
Poco::Net::uninitializeSSL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::http::inherit_proxy()
|
void API::http::set_proxy(const string &hostport, const string &userpw)
|
||||||
{
|
{
|
||||||
// TODO: Test proxy.
|
// TODO: Test proxy.
|
||||||
string proxy, userpw;
|
|
||||||
parent.get_proxy(proxy, userpw);
|
|
||||||
|
|
||||||
size_t pos = proxy.find(':');
|
|
||||||
if (pos == string::npos)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HTTPSClientSession::ProxyConfig proxyconfig;
|
HTTPSClientSession::ProxyConfig proxyconfig;
|
||||||
proxyconfig.host = proxy.substr(0, pos);
|
size_t pos = hostport.find(':');
|
||||||
proxyconfig.port = std::stoi(proxy.substr(pos + 1));
|
|
||||||
|
proxyconfig.host = hostport.substr(0, pos);
|
||||||
|
if (pos != string::npos)
|
||||||
|
{
|
||||||
|
proxyconfig.port = std::stoi(hostport.substr(pos + 1));
|
||||||
|
}
|
||||||
|
|
||||||
if (!userpw.empty())
|
if (!userpw.empty())
|
||||||
{
|
{
|
||||||
pos = userpw.find(':');
|
pos = userpw.find(':');
|
||||||
if (pos == string::npos)
|
proxyconfig.username = userpw.substr(0, pos);
|
||||||
|
if (pos != string::npos)
|
||||||
{
|
{
|
||||||
proxyconfig.username = userpw;
|
proxyconfig.password = userpw.substr(pos + 1);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
proxyconfig.username = userpw.substr(0, pos);
|
|
||||||
proxyconfig.password = std::stoi(userpw.substr(pos + 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ API::API(const string &instance, const string &access_token)
|
||||||
, _useragent(string("mastodon-cpp/") + global::version)
|
, _useragent(string("mastodon-cpp/") + global::version)
|
||||||
, _http(*this, instance, access_token)
|
, _http(*this, instance, access_token)
|
||||||
, _exceptions(false)
|
, _exceptions(false)
|
||||||
, _proxy("")
|
|
||||||
, _proxy_userpw("")
|
|
||||||
{
|
{
|
||||||
bool fash = false;
|
bool fash = false;
|
||||||
const std::regex re_gab("(?:\\.|^)gab\\.[^\\.]+$");
|
const std::regex re_gab("(?:\\.|^)gab\\.[^\\.]+$");
|
||||||
|
@ -293,18 +291,9 @@ bool API::exceptions() const
|
||||||
return _exceptions;
|
return _exceptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::set_proxy(const string &proxy, const string &userpw)
|
void API::set_proxy(const string &hostport, const string &userpw)
|
||||||
{
|
{
|
||||||
_proxy = proxy;
|
_http.set_proxy(hostport, userpw);
|
||||||
_proxy_userpw = userpw;
|
|
||||||
|
|
||||||
_http.inherit_proxy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void API::get_proxy(string &proxy, string &userpw) const
|
|
||||||
{
|
|
||||||
proxy = _proxy;
|
|
||||||
userpw = _proxy_userpw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const parameters API::delete_params(const parameters ¶ms,
|
const parameters API::delete_params(const parameters ¶ms,
|
||||||
|
|
|
@ -143,11 +143,14 @@ namespace Mastodon
|
||||||
std::mutex &get_mutex();
|
std::mutex &get_mutex();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Inherit proxy from parent. Do not call this.
|
* @brief Set proxy. Do not call this directly.
|
||||||
|
*
|
||||||
|
* @param hostport host[:port]
|
||||||
|
* @param userpw user[:password]
|
||||||
*
|
*
|
||||||
* @since 0.110.0
|
* @since 0.110.0
|
||||||
*/
|
*/
|
||||||
void inherit_proxy();
|
void set_proxy(const string &hostport, const string &userpw);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const API &parent;
|
const API &parent;
|
||||||
|
@ -445,25 +448,15 @@ namespace Mastodon
|
||||||
/*!
|
/*!
|
||||||
* @brief Sets the proxy.
|
* @brief Sets the proxy.
|
||||||
*
|
*
|
||||||
* Since mastodon-cpp is built on libcurl, it respects the same
|
* Both the username and the password will be URL decoded
|
||||||
* proxy environment variables. See `man curl`.
|
* before use.
|
||||||
*
|
*
|
||||||
* @param proxy host:port
|
* @param hostport host[:port]
|
||||||
* @param userpw username[:password] (optional)
|
* @param userpw username[:password] (optional)
|
||||||
*
|
*
|
||||||
* @since 0.15.0
|
* @since 0.15.0
|
||||||
*/
|
*/
|
||||||
void set_proxy(const string &proxy, const string &userpw = "");
|
void set_proxy(const string &hostport, const string &userpw = "");
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief For internal use
|
|
||||||
*
|
|
||||||
* @param proxy URL
|
|
||||||
* @param userpw username:password
|
|
||||||
*
|
|
||||||
* @since 0.15.1
|
|
||||||
*/
|
|
||||||
void get_proxy(string &proxy, string &userpw) const;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Make a GET request that doesn't require parameters.
|
* @brief Make a GET request that doesn't require parameters.
|
||||||
|
@ -652,8 +645,6 @@ namespace Mastodon
|
||||||
string _useragent;
|
string _useragent;
|
||||||
http _http;
|
http _http;
|
||||||
bool _exceptions;
|
bool _exceptions;
|
||||||
string _proxy;
|
|
||||||
string _proxy_userpw;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Converts map of parameters into a string.
|
* @brief Converts map of parameters into a string.
|
||||||
|
|
Reference in New Issue