Merge branch v2.11 into v3.2

This commit is contained in:
kevinpollet 2024-11-12 16:24:22 +01:00
commit b7b4dd9554
No known key found for this signature in database
GPG key ID: 0C9A5DDD1B292453
43 changed files with 1094 additions and 789 deletions

View file

@ -3,7 +3,7 @@ package dashboard
import (
"io/fs"
"net/http"
"net/url"
"strings"
"github.com/gorilla/mux"
"github.com/traefik/traefik/v3/webui"
@ -25,7 +25,8 @@ func Append(router *mux.Router, customAssets fs.FS) {
router.Methods(http.MethodGet).
Path("/").
HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
http.Redirect(resp, req, safePrefix(req)+"/dashboard/", http.StatusFound)
prefix := strings.TrimSuffix(req.Header.Get("X-Forwarded-Prefix"), "/")
http.Redirect(resp, req, prefix+"/dashboard/", http.StatusFound)
})
router.Methods(http.MethodGet).
@ -58,21 +59,3 @@ func (g Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.FileServerFS(assets).ServeHTTP(w, r)
}
func safePrefix(req *http.Request) string {
prefix := req.Header.Get("X-Forwarded-Prefix")
if prefix == "" {
return ""
}
parse, err := url.Parse(prefix)
if err != nil {
return ""
}
if parse.Host != "" {
return ""
}
return parse.Path
}