add host server config parameter

This commit is contained in:
Kirill Nikiforov
2026-04-14 06:26:52 +04:00
parent aa0546ff37
commit 64681e2aac
7 changed files with 18 additions and 13 deletions

View File

@@ -10,7 +10,7 @@ import (
)
func ListenAndServeLoopbackHTTPRedirect(
httpPort string,
httpAddr string,
httpsPort string,
handler http.Handler,
allowedPaths ...string,
@@ -23,7 +23,7 @@ func ListenAndServeLoopbackHTTPRedirect(
allowlist[path] = struct{}{}
}
return http.ListenAndServe(httpPort, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
return http.ListenAndServe(httpAddr, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if isLoopbackAllowedPath(req, allowlist) {
if hasValidLoopbackHTTPToken(req) {
handler.ServeHTTP(w, req)
@@ -35,16 +35,14 @@ func ListenAndServeLoopbackHTTPRedirect(
}
host := req.Host
if strings.Contains(host, httpPort) {
host = strings.Split(host, httpPort)[0]
if h, _, err := net.SplitHostPort(host); err == nil {
host = h
}
if httpsPort != "443" {
host = net.JoinHostPort(host, httpsPort)
}
targetURL := "https://" + host + req.URL.String()
if httpsPort != ":443" {
targetURL = "https://" + host + httpsPort + req.URL.String()
}
http.Redirect(w, req, targetURL, http.StatusTemporaryRedirect)
http.Redirect(w, req, "https://"+host+req.URL.RequestURI(), http.StatusTemporaryRedirect)
}))
}