mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 21:42:39 +00:00
first impl for subdomains
This commit is contained in:
parent
db21c2cf0a
commit
96b0d87843
@ -17,6 +17,25 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
/*
|
||||
* Copy `curl` behavior instead of `wget` as it seems to be more flexible.
|
||||
* `curl` strips leading dot and accepts url gitlab.com as a match for no_proxy .gitlab.com,
|
||||
* while `wget` does an exact match.
|
||||
* */
|
||||
std::string buildPocoRegexpEntryWithoutLeadingDot(const std::string & host)
|
||||
{
|
||||
std::string_view view_without_leading_dot = host;
|
||||
if (host[0] == '.')
|
||||
{
|
||||
view_without_leading_dot = std::string_view {host.begin() + 1u, host.end()};
|
||||
}
|
||||
|
||||
return RE2::QuoteMeta(view_without_leading_dot);
|
||||
}
|
||||
|
||||
/*
|
||||
* Even though there is not an RFC that defines NO_PROXY, it is usually a comma-separated list of domains.
|
||||
* Different tools implement their own versions of `NO_PROXY` support. Some support CIDR blocks, some support wildcard etc.
|
||||
@ -31,11 +50,15 @@ namespace DB
|
||||
* */
|
||||
std::string buildPocoNonProxyHosts(const std::string & no_proxy_hosts)
|
||||
{
|
||||
static constexpr auto OR_SEPARATOR = "|";
|
||||
static constexpr auto MATCH_ANYTHING = R"((.*?))";
|
||||
static constexpr auto MATCH_SUBDOMAINS_REGEX = R"((?:.*\.)?)";
|
||||
|
||||
bool match_any_host = no_proxy_hosts.size() == 1 && no_proxy_hosts[0] == '*';
|
||||
|
||||
if (match_any_host)
|
||||
{
|
||||
return "(.*?)";
|
||||
return MATCH_ANYTHING;
|
||||
}
|
||||
|
||||
std::string host;
|
||||
@ -52,10 +75,14 @@ std::string buildPocoNonProxyHosts(const std::string & no_proxy_hosts)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
result.append("|");
|
||||
result.append(OR_SEPARATOR);
|
||||
}
|
||||
|
||||
result.append(RE2::QuoteMeta(host));
|
||||
auto escaped_host_without_leading_dot = buildPocoRegexpEntryWithoutLeadingDot(host);
|
||||
|
||||
result.append(MATCH_SUBDOMAINS_REGEX);
|
||||
result.append(escaped_host_without_leading_dot);
|
||||
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
@ -63,6 +90,8 @@ std::string buildPocoNonProxyHosts(const std::string & no_proxy_hosts)
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Poco::Net::HTTPClientSession::ProxyConfig proxyConfigurationToPocoProxyConfig(const DB::ProxyConfiguration & proxy_configuration)
|
||||
{
|
||||
Poco::Net::HTTPClientSession::ProxyConfig poco_proxy_config;
|
||||
|
@ -10,7 +10,7 @@ TEST(ProxyConfigurationToPocoProxyConfiguration, TestNoProxyHostRegexBuild)
|
||||
|
||||
auto poco_proxy_configuration = DB::proxyConfigurationToPocoProxyConfig(proxy_configuration);
|
||||
|
||||
ASSERT_EQ(poco_proxy_configuration.nonProxyHosts, "localhost|127\\.0\\.0\\.1|some_other_domain\\:8080|sub\\-domain\\.domain\\.com");
|
||||
ASSERT_EQ(poco_proxy_configuration.nonProxyHosts, R"((?:.*\.)?localhost|(?:.*\.)?127\.0\.0\.1|(?:.*\.)?some_other_domain\:8080|(?:.*\.)?sub\-domain\.domain\.com)");
|
||||
}
|
||||
|
||||
TEST(ProxyConfigurationToPocoProxyConfiguration, TestNoProxyHostRegexBuildMatchAnything)
|
||||
|
Loading…
Reference in New Issue
Block a user