fix: preserve IPv6 brackets in redirects

Re-wrap bare IPv6 hosts after stripping ports so HTTPS redirect URLs stay valid. Add a regression test covering bracketed IPv6 hosts in redirect responses.
This commit is contained in:
wjqserver 2026-04-07 20:31:10 +08:00
parent 9e57f5a5f5
commit 121679b44e
2 changed files with 23 additions and 0 deletions

View file

@ -332,6 +332,9 @@ func buildRedirectServer(engine *Engine, cfg runConfig) (*http.Server, error) {
if parsedHost, _, err := net.SplitHostPort(host); err == nil {
host = parsedHost
if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
host = "[" + host + "]"
}
}
targetURL := "https://" + host