Merge branch 'develop'
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2019-09-06 02:34:30 +02:00
commit 095645ba6e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 19 additions and 22 deletions

View File

@ -14,10 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <iostream>
#include <exception>
#include <memory>
#include <regex>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/HTTPRequest.h>
@ -35,6 +35,9 @@ using std::endl;
using std::istream;
using std::unique_ptr;
using std::make_unique;
using std::regex;
using std::regex_search;
using std::smatch;
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPRequest;
@ -47,31 +50,25 @@ void set_proxy()
{
try
{
HTTPClientSession::ProxyConfig proxy;
string proxy_env = Environment::get("http_proxy");
size_t pos;
HTTPSClientSession::ProxyConfig proxyconfig;
string env_proxy = Environment::get("http_proxy");
regex re_proxy("^(?:https?://)?(?:([^:]+):?([^@]*)@)?" // user:password
"([^:]+):([[:digit:]]+/?)"); // host:port
smatch match;
// Only keep text between // and /.
if ((pos = proxy_env.find("//")) != string::npos)
if (regex_search(env_proxy, match, re_proxy))
{
proxy_env = proxy_env.substr(pos + 2);
}
if ((pos = proxy_env.find('/')) != string::npos)
{
proxy_env = proxy_env.substr(0, pos);
}
string username, password;
Poco::URI::decode(match[1].str(), username);
Poco::URI::decode(match[2].str(), password);
if ((pos = proxy_env.find(':')) != string::npos)
{
proxy.host = proxy_env.substr(0, pos);
proxy.port = std::stoi(proxy_env.substr(pos + 1));
}
else
{
proxy.host = proxy_env;
}
proxyconfig.host = match[3].str();
proxyconfig.port = std::stoi(match[4].str());
proxyconfig.username = username;
proxyconfig.password = password;
HTTPClientSession::setGlobalProxyConfig(proxy);
HTTPSClientSession::setGlobalProxyConfig(proxyconfig);
}
}
catch (const std::exception &)
{