in src/api_proxy/path_matcher/path_matcher_node.cc [138:176]
void PathMatcherNode::LookupPath(const RequestPathParts::const_iterator current,
const RequestPathParts::const_iterator end,
HttpMethod http_method,
PathMatcherLookupResult* result) const {
// base case
if (current == end) {
if (!GetResultForHttpMethod(http_method, result)) {
// If we didn't find a wrapper graph at this node, check if we have one
// in a wildcard (**) child. If we do, use it. This will ensure we match
// the root with wildcard templates.
auto pair = children_.find(HttpTemplate::kWildCardPathKey);
if (pair != children_.end()) {
const auto& child = pair->second;
child->GetResultForHttpMethod(http_method, result);
}
}
return;
}
if (LookupPathFromChild(*current, current, end, http_method, result)) {
return;
}
// For wild card node, keeps searching for next path segment until either
// 1) reaching the end (/foo/** case), or 2) all remaining segments match
// one of child branches (/foo/**/bar/xyz case).
if (wildcard_) {
LookupPath(current + 1, end, http_method, result);
// Since only constant segments are allowed after wild card, no need to
// search another wild card nodes from children, so bail out here.
return;
}
for (const std::string& child_key :
{HttpTemplate::kSingleParameterKey, HttpTemplate::kWildCardPathPartKey,
HttpTemplate::kWildCardPathKey}) {
if (LookupPathFromChild(child_key, current, end, http_method, result)) {
return;
}
}
}