MCPcopy
hub / github.com/caddyserver/caddy / asciiServerNameForMatch

Function asciiServerNameForMatch

modules/caddytls/matchers.go:83–118  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

81}
82
83func asciiServerNameForMatch(name string) string {
84 if name == "" {
85 return name
86 }
87
88 // Fast path: if the name is pure ASCII, skip idna.ToASCII.
89 // SNI values on the wire are always ASCII (RFC 6066), and most
90 // config patterns are also ASCII. For pure ASCII input, idna.ToASCII
91 // only validates and lowercases, which is equivalent to our fallback.
92 if isPureASCII(name) {
93 return strings.ToLower(name)
94 }
95
96 // Config can use Unicode IDNs.
97 ascii, err := idna.ToASCII(name)
98 if err == nil {
99 return strings.ToLower(ascii)
100 }
101
102 if !strings.Contains(name, "*") {
103 return strings.ToLower(name)
104 }
105
106 labels := strings.Split(name, ".")
107 for i, label := range labels {
108 if label == "" || label == "*" {
109 continue
110 }
111 ascii, err := idna.ToASCII(label)
112 if err != nil {
113 return strings.ToLower(name)
114 }
115 labels[i] = strings.ToLower(ascii)
116 }
117 return strings.Join(labels, ".")
118}
119
120func isPureASCII(s string) bool {
121 for i := 0; i < len(s); i++ {

Callers 2

MatchMethod · 0.85
TLSConfigMethod · 0.85

Calls 1

isPureASCIIFunction · 0.85

Tested by

no test coverage detected