30 #include "absl/status/status.h"
31 #include "absl/status/statusor.h"
32 #include "absl/strings/match.h"
33 #include "absl/strings/str_cat.h"
58 std::transform(domain_pattern.begin(), domain_pattern.end(),
59 domain_pattern.begin(),
60 [](
unsigned char c) { return std::tolower(c); });
61 std::transform(expected_host_name.begin(), expected_host_name.end(),
62 expected_host_name.begin(),
63 [](
unsigned char c) { return std::tolower(c); });
64 if (match_type == EXACT_MATCH) {
65 return domain_pattern == expected_host_name;
66 }
else if (match_type == SUFFIX_MATCH) {
68 if (expected_host_name.size() < domain_pattern.size())
return false;
71 expected_host_name.size() -
72 pattern_suffix.size());
73 return pattern_suffix == host_suffix;
74 }
else if (match_type == PREFIX_MATCH) {
76 if (expected_host_name.size() < domain_pattern.size())
return false;
78 domain_pattern.size() - 1);
80 pattern_prefix.size());
81 return pattern_prefix == host_prefix;
83 return match_type == UNIVERSE_MATCH;
88 if (domain_pattern.
empty())
return INVALID_MATCH;
90 if (domain_pattern ==
"*")
return UNIVERSE_MATCH;
91 if (domain_pattern[0] ==
'*')
return SUFFIX_MATCH;
92 if (domain_pattern[domain_pattern.
size() - 1] ==
'*')
return PREFIX_MATCH;
110 MatchType best_match_type = INVALID_MATCH;
114 for (
size_t i = 0;
i < vhost_iterator.
Size(); ++
i) {
119 const MatchType match_type = DomainPatternMatchType(domain_pattern);
122 if (match_type > best_match_type)
continue;
123 if (match_type == best_match_type &&
128 if (!DomainMatch(match_type, domain_pattern, domain))
continue;
131 best_match_type = match_type;
133 if (best_match_type == EXACT_MATCH)
break;
135 if (best_match_type == EXACT_MATCH)
break;
142 bool HeadersMatch(
const std::vector<HeaderMatcher>& header_matchers,
144 for (
const auto& header_matcher : header_matchers) {
147 initial_metadata, header_matcher.name(), &concatenated_value))) {
154 bool UnderFraction(
const uint32_t fraction_per_million) {
156 const uint32_t random_number = rand() % 1000000;
157 return random_number < fraction_per_million;
165 for (
size_t i = 0;
i < route_list_iterator.
Size(); ++
i) {
169 HeadersMatch(
matchers.header_matchers, initial_metadata) &&
170 (!
matchers.fraction_per_million.has_value() ||
171 UnderFraction(*
matchers.fraction_per_million))) {
175 return absl::nullopt;
179 return DomainPatternMatchType(domain_pattern) != INVALID_MATCH;
189 return absl::nullopt;
190 }
else if (header_name ==
"content-type") {
191 return "application/grpc";
193 return initial_metadata->
GetStringValue(header_name, concatenated_value);
205 if (cluster_weight !=
nullptr) {
221 XdsRouting::GeneratePerHttpFilterConfigsResult
223 const std::vector<XdsListenerResource::HttpConnectionManager::HttpFilter>&
232 for (
const auto& http_filter : http_filters) {
237 http_filter.config.config_proto_type_name);
247 FindFilterConfigOverride(http_filter.name, vhost,
route,
250 auto method_config_field =
252 if (!method_config_field.ok()) {
256 "failed to generate method config for HTTP filter ", http_filter.name,
257 ": ", method_config_field.status().ToString()));
260 result.per_filter_configs[method_config_field->service_config_field_name]
261 .push_back(method_config_field->element);