fix cloning failure due to trailing slash redirects
1 file changed, 11 insertions(+), 2 deletions(-)
changed files
M routes/handler.go → routes/handler.go
@@ -4,6 +4,7 @@ import ( "log" "net/http" "path" + "strings" "github.com/dimfeld/httptreemux/v5"@@ -47,7 +48,11 @@ d.InfoRefs(w, r, params) } else if rest == "git-upload-pack" && r.Method == "POST" { d.UploadPack(w, r, params) } else if r.Method == "GET" { - d.RepoIndex(w, r, params) + if fixed, found := strings.CutSuffix(r.URL.Path, "/"); found { + http.Redirect(w, r, fixed, http.StatusPermanentRedirect) + } else { + d.RepoIndex(w, r, params) + } } }@@ -68,7 +73,7 @@ mux.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) { d.Write404(w) } - mux.RedirectTrailingSlash = true + mux.RedirectTrailingSlash = false mux.GET("/", d.Index) mux.GET("/static/:file", d.ServeStatic)@@ -84,6 +89,8 @@ mux.GET("/:name/commit/:ref/*file", d.FileDiff) mux.GET("/:name/refs/", d.Refs) mux.GET("/:name", d.Multiplex) mux.POST("/:name", d.Multiplex) + mux.GET("/:name/", d.Multiplex) + mux.POST("/:name/", d.Multiplex) mux.GET("/:name/*rest", d.Multiplex) mux.POST("/:name/*rest", d.Multiplex)@@ -98,6 +105,8 @@ mux.GET("/:category/:name/commit/:ref/*file", d.FileDiff) mux.GET("/:category/:name/refs/", d.Refs) mux.GET("/:category/:name", d.Multiplex) mux.POST("/:category/:name", d.Multiplex) + mux.GET("/:category/:name/", d.Multiplex) + mux.POST("/:category/:name/", d.Multiplex) mux.GET("/:category/:name/*rest", d.Multiplex) mux.POST("/:category/:name/*rest", d.Multiplex)