mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-04 05:00:24 +08:00
支持中文域名(转换punycode后)访问
This commit is contained in:
@@ -6,8 +6,12 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||
"golang.org/x/net/idna"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var normalServerNameReg = regexp.MustCompile(`^[a-zA-Z0-9.-]+$`)
|
||||
|
||||
type ServerConfig struct {
|
||||
Id int64 `yaml:"id" json:"id"` // ID
|
||||
ClusterId int64 `yaml:"clusterId" json:"clusterId"` // 集群ID
|
||||
@@ -341,6 +345,14 @@ func (this *ServerConfig) AllStrictNames() []string {
|
||||
if len(name) > 0 {
|
||||
if !configutils.IsFuzzyDomain(name) {
|
||||
result = append(result, name)
|
||||
|
||||
// unicode domain
|
||||
if !normalServerNameReg.MatchString(name) {
|
||||
asciiName, err := idna.ToASCII(name)
|
||||
if err == nil && len(asciiName) > 0 {
|
||||
result = append(result, asciiName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,12 +361,28 @@ func (this *ServerConfig) AllStrictNames() []string {
|
||||
if len(name) > 0 {
|
||||
if !configutils.IsFuzzyDomain(name) {
|
||||
result = append(result, name)
|
||||
|
||||
// unicode domain
|
||||
if !normalServerNameReg.MatchString(name) {
|
||||
asciiName, err := idna.ToASCII(name)
|
||||
if err == nil && len(asciiName) > 0 {
|
||||
result = append(result, asciiName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, name := range serverName.SubNames {
|
||||
if len(name) > 0 {
|
||||
if !configutils.IsFuzzyDomain(name) {
|
||||
result = append(result, name)
|
||||
|
||||
// unicode domain
|
||||
if !normalServerNameReg.MatchString(name) {
|
||||
asciiName, err := idna.ToASCII(name)
|
||||
if err == nil && len(asciiName) > 0 {
|
||||
result = append(result, asciiName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user