From: Sergey Matveev Date: Tue, 3 Mar 2026 11:30:23 +0000 (+0300) Subject: Normalise IPv6 hostnames X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;p=godlighty.git Normalise IPv6 hostnames --- diff --git a/godlighty.go b/godlighty.go index 60c1c4b..8233c4b 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.11.0" +const Version = "godlighty/0.12.0" var BindAddr string diff --git a/handler.go b/handler.go index e31a034..abdd27b 100644 --- a/handler.go +++ b/handler.go @@ -361,5 +361,10 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { host = r.Host } + if len(host) > 2 && host[0] == '[' && host[len(host)-1] == ']' { + if ip6 := net.ParseIP(host[1 : len(host)-1]); ip6 != nil { + host = "[" + ip6.String() + "]" + } + } h.Handle(w, r, host, Hosts[host]) }