summaryrefslogtreecommitdiffstats
path: root/routers/web/web.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-12-22 10:39:28 +0000
committerGitHub <noreply@github.com>2021-12-22 10:39:28 +0000
commit62dcf1a6fb8f4cf935e7ca288406402d243507c0 (patch)
tree0150ef5d7377dc6bb1459a51e711ab9f720e50bc /routers/web/web.go
parenta9ed1c5c7c6c85ae280e6a13ca0d4e665945efb4 (diff)
downloadgitea-62dcf1a6fb8f4cf935e7ca288406402d243507c0.tar.gz
gitea-62dcf1a6fb8f4cf935e7ca288406402d243507c0.zip
Add NotFound handler (#18062)
PR #17997 means that urls with terminal '/' are no longer immediately mapped to the url without a terminal slash. However, it has revealed that the NotFound handler appears to have been lost. This PR adds back in a NotFound handler that simply redirects to a path without the terminal slash or runs the NotFound handler. Fix #18060 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers/web/web.go')
-rw-r--r--routers/web/web.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/routers/web/web.go b/routers/web/web.go
index 41c4e122fb..ebd0995df8 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1078,4 +1078,14 @@ func RegisterRoutes(m *web.Route) {
if setting.API.EnableSwagger {
m.Get("/swagger.v1.json", SwaggerV1Json)
}
+ m.NotFound(func(w http.ResponseWriter, req *http.Request) {
+ escapedPath := req.URL.EscapedPath()
+ if len(escapedPath) > 1 && escapedPath[len(escapedPath)-1] == '/' {
+ http.Redirect(w, req, setting.AppSubURL+escapedPath[:len(escapedPath)-1], http.StatusTemporaryRedirect)
+ return
+ }
+ ctx := context.GetContext(req)
+ ctx.NotFound("", nil)
+ })
+
}