diff --git a/source/common/router/config_impl.cc b/source/common/router/config_impl.cc index d5301073fd1a..21b891ae79b3 100644 --- a/source/common/router/config_impl.cc +++ b/source/common/router/config_impl.cc @@ -851,7 +851,7 @@ RouteConstSharedPtr VirtualHostImpl::getRouteFromEntries(const Http::HeaderMap& const VirtualHostImpl* RouteMatcher::findVirtualHost(const Http::HeaderMap& headers) const { // Fast path the case where we only have a default virtual host. - if (virtual_hosts_.empty() && default_virtual_host_) { + if (virtual_hosts_.empty() && wildcard_virtual_host_suffixes_.empty() && default_virtual_host_) { return default_virtual_host_.get(); } diff --git a/test/common/router/config_impl_test.cc b/test/common/router/config_impl_test.cc index 9951064466b8..2b1e7fe587a1 100644 --- a/test/common/router/config_impl_test.cc +++ b/test/common/router/config_impl_test.cc @@ -535,6 +535,31 @@ TEST(RouteMatcherTest, TestRoutes) { } } +TEST(RouteMatcherTest, TestRoutesWithWildcardAndDefaultOnly) { + std::string yaml = R"EOF( +virtual_hosts: + - name: wildcard + domains: ["*.solo.io"] + routes: + - match: { prefix: "/" } + route: { cluster: "wildcard" } + - name: default + domains: ["*"] + routes: + - match: { prefix: "/" } + route: { cluster: "default" } + )EOF"; + + const auto proto_config = parseRouteConfigurationFromV2Yaml(yaml); + NiceMock factory_context; + TestConfigImpl config(proto_config, factory_context, true); + + EXPECT_EQ("wildcard", + config.route(genHeaders("gloo.solo.io", "/", "GET"), 0)->routeEntry()->clusterName()); + EXPECT_EQ("default", + config.route(genHeaders("example.com", "/", "GET"), 0)->routeEntry()->clusterName()); +} + TEST(RouteMatcherTest, TestRoutesWithInvalidRegex) { std::string invalid_route = R"EOF( virtual_hosts: