This commit is contained in:
Willy Kloucek
2021-09-15 18:18:58 +02:00
parent cb3a5b811d
commit 09b4850965
2 changed files with 16 additions and 10 deletions

View File

@@ -0,0 +1,6 @@
Bugfix: redirect invalid links to oC Web
Invalid links ending with a slash(eg. https://foo.bar/index.php/apps/pdfviewer/) have not been redirected to ownCloud Web. Instead the former 404 not found status page was displayed.
https://github.com/owncloud/ocis/pull/2493
https://github.com/owncloud/ocis/pull/2512

View File

@@ -137,11 +137,17 @@ func (p Web) Static(ttl int) http.HandlerFunc {
assets.Logger(p.logger),
assets.Config(p.config),
)
notFoundFunc := func(w http.ResponseWriter, r *http.Request) {
// TODO: replace the redirect with a not found page containing a link to the Web UI
http.Redirect(w, r, rootWithSlash, http.StatusTemporaryRedirect)
}
static := http.StripPrefix(
rootWithSlash,
interceptNotFound(
http.FileServer(assets),
rootWithSlash,
notFoundFunc,
),
)
@@ -158,16 +164,11 @@ func (p Web) Static(ttl int) http.HandlerFunc {
rootWithSlash,
http.StatusMovedPermanently,
)
return
}
if r.URL.Path != rootWithSlash && strings.HasSuffix(r.URL.Path, "/") {
http.NotFound(
w,
r,
)
notFoundFunc(w, r)
return
}
@@ -184,13 +185,12 @@ func (p Web) Static(ttl int) http.HandlerFunc {
}
}
func interceptNotFound(h http.Handler, root string) http.HandlerFunc {
func interceptNotFound(h http.Handler, notFoundFunc func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
notFoundInterceptor := &NotFoundInterceptor{ResponseWriter: w}
h.ServeHTTP(notFoundInterceptor, r)
if notFoundInterceptor.status == http.StatusNotFound {
http.Redirect(w, r, root, http.StatusTemporaryRedirect)
// TODO: replace the redirect with a not found page containing a link to the Web UI
notFoundFunc(w, r)
}
}
}