mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-27 04:07:28 +00:00
caddytls: skip idna.ToASCII for pure ASCII SNI values (#7770)
SNI is always ASCII on the wire (RFC 6066), and most config patterns are also ASCII. For pure ASCII input, idna.ToASCII only validates and lowercases, which is equivalent to a simple strings.ToLower. Add a fast path to avoid the overhead of idna.ToASCII in the common case.
This commit is contained in:
parent
4d60d936ed
commit
86121c860f
1 changed files with 18 additions and 1 deletions
|
|
@ -85,7 +85,15 @@ func asciiServerNameForMatch(name string) string {
|
|||
return name
|
||||
}
|
||||
|
||||
// SNI is ASCII on the wire, but config can use Unicode IDNs.
|
||||
// Fast path: if the name is pure ASCII, skip idna.ToASCII.
|
||||
// SNI values on the wire are always ASCII (RFC 6066), and most
|
||||
// config patterns are also ASCII. For pure ASCII input, idna.ToASCII
|
||||
// only validates and lowercases, which is equivalent to our fallback.
|
||||
if isPureASCII(name) {
|
||||
return strings.ToLower(name)
|
||||
}
|
||||
|
||||
// Config can use Unicode IDNs.
|
||||
ascii, err := idna.ToASCII(name)
|
||||
if err == nil {
|
||||
return strings.ToLower(ascii)
|
||||
|
|
@ -109,6 +117,15 @@ func asciiServerNameForMatch(name string) string {
|
|||
return strings.Join(labels, ".")
|
||||
}
|
||||
|
||||
func isPureASCII(s string) bool {
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] >= 0x80 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// UnmarshalCaddyfile sets up the MatchServerName from Caddyfile tokens. Syntax:
|
||||
//
|
||||
// sni <domains...>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue