fix favicon redirection path

This commit is contained in:
yusing 2025-01-12 13:14:31 +08:00
parent fcbb51dce7
commit 645a58464c

View file

@ -9,6 +9,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"path"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -157,6 +158,7 @@ func sanitizeName(name string) string {
} }
func findIcon(r route.HTTPRoute, req *http.Request, uri string) (icon []byte, status int, errMsg string) { func findIcon(r route.HTTPRoute, req *http.Request, uri string) (icon []byte, status int, errMsg string) {
// FIXME: invalidate cache on route change
key := r.TargetName() key := r.TargetName()
icon, ok := loadIconCache(key) icon, ok := loadIconCache(key)
if ok { if ok {
@ -201,6 +203,10 @@ func findIconSlow(r route.HTTPRoute, req *http.Request, uri string) (icon []byte
return nil, http.StatusBadGateway, "connection error" return nil, http.StatusBadGateway, "connection error"
default: default:
if loc := c.Header().Get("Location"); loc != "" { if loc := c.Header().Get("Location"); loc != "" {
loc = path.Clean(loc)
if !strings.HasPrefix(loc, "/") {
loc = "/" + loc
}
if loc == newReq.URL.Path { if loc == newReq.URL.Path {
return nil, http.StatusBadGateway, "circular redirect" return nil, http.StatusBadGateway, "circular redirect"
} }