From 5edc02d033a9ebe69e6ae7dda12ac0a9c716aa27 Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Sun, 26 Feb 2023 16:19:35 +0200 Subject: [PATCH 1/3] Commit --- routers/common/middleware.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/routers/common/middleware.go b/routers/common/middleware.go index 4f9d43c362182..fcee38c78da2b 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -5,6 +5,7 @@ package common import ( "fmt" + "github.com/go-chi/chi/v5" "net/http" "strings" @@ -50,6 +51,28 @@ func Middlewares() []func(http.Handler) http.Handler { handlers = append(handlers, middleware.StripSlashes) + handlers = append(handlers, func(next http.Handler) http.Handler { + return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { + var path string + rctx := chi.RouteContext(req.Context()) + if rctx != nil && rctx.RoutePath != "" { + path = rctx.RoutePath + } else { + path = req.URL.Path + } + fmt.Println(strings.HasPrefix(path, "//")) + if len(path) > 1 && strings.HasPrefix(path, "//") { + newPath := path[1:] + if rctx == nil { + req.URL.Path = newPath + } else { + rctx.RoutePath = newPath + } + } + next.ServeHTTP(resp, req) + }) + }) + if !setting.Log.DisableRouterLog { handlers = append(handlers, routing.NewLoggerHandler()) } From c288da466051d06ad52939854d56e11e414d09ed Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Sun, 26 Feb 2023 16:26:54 +0200 Subject: [PATCH 2/3] Commit --- routers/common/middleware.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/common/middleware.go b/routers/common/middleware.go index fcee38c78da2b..c808747bd2392 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -60,7 +60,6 @@ func Middlewares() []func(http.Handler) http.Handler { } else { path = req.URL.Path } - fmt.Println(strings.HasPrefix(path, "//")) if len(path) > 1 && strings.HasPrefix(path, "//") { newPath := path[1:] if rctx == nil { From 72cc9d31d2d34577c8c9f1459df35a2b679381f8 Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Sun, 26 Feb 2023 16:29:22 +0200 Subject: [PATCH 3/3] Commit --- routers/common/middleware.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/common/middleware.go b/routers/common/middleware.go index c808747bd2392..2765577b021ea 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -5,7 +5,6 @@ package common import ( "fmt" - "github.com/go-chi/chi/v5" "net/http" "strings" @@ -17,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/web/routing" "github.com/chi-middleware/proxy" + "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" )