diff --git a/include/export/json.hpp b/include/export/json.hpp index 1afa662..40b8e88 100644 --- a/include/export/json.hpp +++ b/include/export/json.hpp @@ -27,7 +27,7 @@ namespace Export using std::string; /*! - * @brief Export as JSON array. + * @brief Export as %JSON array. * * @since 0.8.0 * diff --git a/include/export/rss.hpp b/include/export/rss.hpp index 8fe9495..4840f03 100644 --- a/include/export/rss.hpp +++ b/include/export/rss.hpp @@ -27,7 +27,7 @@ namespace Export using std::string; /*! - * @brief Export as RSS feed. + * @brief Export as %RSS feed. * * @since 0.8.0 * diff --git a/man/remwharead.1.adoc b/man/remwharead.1.adoc index 8aa89dd..1de1ca1 100644 --- a/man/remwharead.1.adoc +++ b/man/remwharead.1.adoc @@ -2,7 +2,7 @@ :doctype: manpage :Author: tastytea :Email: tastytea@tastytea.de -:Date: 2019-09-06 +:Date: 2019-09-20 :Revision: 0.0.0 :man source: remwharead :man manual: General Commands Manual @@ -160,8 +160,10 @@ Currently only HTTP and HTTPS are supported. == PROXY SUPPORT *remwharead* supports HTTP proxies set via the environment variable -_http_proxy_. Accepted formats are _http://host:port/_ or _host:port_. No SOCKS -proxy support yet, sorry. +_http_proxy_. Accepted formats are: _\http://[user[:password]@]host[:port]/_ or +_[user[:password]@]host[:port]_. No SOCKS proxy support yet, sorry. + +Example: http_proxy="http://localhost:3128/" == FILES diff --git a/src/lib/uri.cpp b/src/lib/uri.cpp index 3953400..02ed9ca 100644 --- a/src/lib/uri.cpp +++ b/src/lib/uri.cpp @@ -40,6 +40,8 @@ namespace remwharead using std::unique_ptr; using std::make_unique; using std::vector; + using std::cerr; + using std::endl; using Poco::Net::HTTPClientSession; using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPRequest; @@ -67,31 +69,37 @@ namespace remwharead try { HTTPClientSession::ProxyConfig proxy; - string proxy_env = Environment::get("http_proxy"); - size_t pos; + const string env_proxy = Environment::get("http_proxy"); + const RegEx re_proxy("^(?:https?://)?(?:([^:]+):?([^@]*)@)?" + "([^:/]+)(?::([\\d]{1,5}))?/?$"); + vector matches; - // Only keep text between // and /. - if ((pos = proxy_env.find("//")) != string::npos) + if (re_proxy.split(env_proxy, matches) >= 4) { - 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); } + 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 &) { // No proxy found, no problem.