mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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>
This commit is contained in:
		@@ -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)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user