首页 > 解决方案 > DomainNameMapping 匹配无效?

问题描述

我有以下 DomainNameMapping ,其中包含以下两个映射。

"*.app.example.com" => A

"*.example.com" => B

当我尝试映射“app.example.com”的主机时,我收到输出 A。我希望 DomainNameMapping 会改为匹配“*.example.com”并返回输出 B。

查看 Netty 源代码,这似乎满足了 matches(String, String) 方法的第一个条件。

static boolean matches(String template, String hostName) {
        if (template.startsWith("*.")) {
            return template.regionMatches(2, hostName, 0, hostName.length())
                || commonSuffixOfLength(hostName, template, template.length() - 1);
        }
        return template.equals(hostName);
}

即,template.regionMatches(2, hostName, 0, hostName.length())在这种情况下为真。为什么允许这种情况匹配?在我看来,模板应该只匹配在 DomainNameMapping 中找到的通配符定义的根域上具有一些子域前缀的主机名。

标签: netty

解决方案


推荐阅读