Files
pages/internal/server/middleware/normalize.go
T
Anya Tokugawa 5321d613b4
Build and publish container images / images (push) Successful in 11m45s
Release container images / release (push) Successful in 21s
feat(feeds): add opt-in Gecko relay and folder shortcuts
Document engine redistribution requirements; exclude upstream engine assets and keep the viewer disabled by default.
2026-11-08 16:14:34 +09:00

61 lines
1.0 KiB
Go

package middleware
import (
"net/http"
"strings"
)
func NormalizePath(
next http.Handler,
) http.Handler {
return http.HandlerFunc(
func(
w http.ResponseWriter,
r *http.Request,
) {
p := r.URL.Path
// Hosted adapter assets use directory-relative module and worker URLs.
// DAV collections also require the slash: removing it conflicts with
// ServeMux's collection redirect and causes an infinite redirect loop.
if strings.HasPrefix(p, "/_/adaptor/") || strings.HasPrefix(p, "/_/api/v1/caldav/") || strings.HasPrefix(p, "/_/api/v1/carddav/") || strings.HasPrefix(p, "/_/api/v1/extension/organizer.feeds/browser/") {
next.ServeHTTP(w, r)
return
}
if p != "/" {
for strings.HasSuffix(
p,
"/",
) {
p = strings.TrimSuffix(
p,
"/",
)
}
if p == "" {
p = "/"
}
if p != r.URL.Path {
http.Redirect(
w,
r,
p,
http.StatusMovedPermanently,
)
return
}
}
next.ServeHTTP(w, r)
},
)
}