fix: preserve loopback access for host configuration

- Keep internal loopback HTTP APIs reachable when the server is bound to a
specific non-loopback host by adding a dedicated 127.0.0.1 listener.

- Move listener address helpers into utils and normalize HTTPS redirect hosts so
IPv6 request hosts are not double-bracketed.
This commit is contained in:
wenjie
2026-04-24 10:29:16 +08:00
parent 1893912ba7
commit 2d67720022
3 changed files with 73 additions and 24 deletions

28
server/utils/listener.go Normal file
View File

@@ -0,0 +1,28 @@
package utils
import (
"fmt"
"net"
"strings"
)
func ListenAddr(host string, port string) string {
if host == "" {
return fmt.Sprintf(":%s", port)
}
return net.JoinHostPort(host, port)
}
func NeedsDedicatedLoopbackListener(host string) bool {
host = strings.TrimSpace(strings.Trim(host, "[]"))
if host == "" {
return false
}
ip := net.ParseIP(host)
if ip == nil {
return !strings.EqualFold(host, "localhost")
}
return !ip.IsLoopback() && !ip.IsUnspecified()
}