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

This commit is contained in:
tastytea 2019-09-20 23:39:23 +02:00
commit 28f194c910
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 35 additions and 25 deletions

View File

@ -27,7 +27,7 @@ namespace Export
using std::string; using std::string;
/*! /*!
* @brief Export as JSON array. * @brief Export as %JSON array.
* *
* @since 0.8.0 * @since 0.8.0
* *

View File

@ -27,7 +27,7 @@ namespace Export
using std::string; using std::string;
/*! /*!
* @brief Export as RSS feed. * @brief Export as %RSS feed.
* *
* @since 0.8.0 * @since 0.8.0
* *

View File

@ -2,7 +2,7 @@
:doctype: manpage :doctype: manpage
:Author: tastytea :Author: tastytea
:Email: tastytea@tastytea.de :Email: tastytea@tastytea.de
:Date: 2019-09-06 :Date: 2019-09-20
:Revision: 0.0.0 :Revision: 0.0.0
:man source: remwharead :man source: remwharead
:man manual: General Commands Manual :man manual: General Commands Manual
@ -160,8 +160,10 @@ Currently only HTTP and HTTPS are supported.
== PROXY SUPPORT == PROXY SUPPORT
*remwharead* supports HTTP proxies set via the environment variable *remwharead* supports HTTP proxies set via the environment variable
_http_proxy_. Accepted formats are _http://host:port/_ or _host:port_. No SOCKS _http_proxy_. Accepted formats are: _\http://[user[:password]@]host[:port]/_ or
proxy support yet, sorry. _[user[:password]@]host[:port]_. No SOCKS proxy support yet, sorry.
Example: http_proxy="http://localhost:3128/"
== FILES == FILES

View File

@ -40,6 +40,8 @@ namespace remwharead
using std::unique_ptr; using std::unique_ptr;
using std::make_unique; using std::make_unique;
using std::vector; using std::vector;
using std::cerr;
using std::endl;
using Poco::Net::HTTPClientSession; using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPRequest; using Poco::Net::HTTPRequest;
@ -67,31 +69,37 @@ namespace remwharead
try try
{ {
HTTPClientSession::ProxyConfig proxy; HTTPClientSession::ProxyConfig proxy;
string proxy_env = Environment::get("http_proxy"); const string env_proxy = Environment::get("http_proxy");
size_t pos; const RegEx re_proxy("^(?:https?://)?(?:([^:]+):?([^@]*)@)?"
"([^:/]+)(?::([\\d]{1,5}))?/?$");
vector<string> matches;
// Only keep text between // and /. if (re_proxy.split(env_proxy, matches) >= 4)
if ((pos = proxy_env.find("//")) != string::npos)
{ {
proxy_env = proxy_env.substr(pos + 2); proxy.username = matches[1];
proxy.password = matches[2];
proxy.host = matches[3];
if (!matches[4].empty())
{
const std::uint32_t &port = std::stoul(matches[4]);
if (port > 65535)
{
throw std::invalid_argument("Port number out of range");
}
proxy.port = port;
}
} }
if ((pos = proxy_env.find('/')) != string::npos)
{
proxy_env = proxy_env.substr(0, pos);
}
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;
}
HTTPClientSession::setGlobalProxyConfig(proxy); HTTPClientSession::setGlobalProxyConfig(proxy);
} }
catch (const Poco::RegularExpressionException &e)
{
cerr << "Error: Proxy could not be set ("
<< e.displayText() << ")\n";
}
catch (const std::invalid_argument &e)
{
cerr << "Error: " << e.what() << endl;
}
catch (const std::exception &) catch (const std::exception &)
{ {
// No proxy found, no problem. // No proxy found, no problem.