]> source.dussan.org Git - gitea.git/commitdiff
Move FCGI req.URL.Path fix-up to the FCGI listener (#15292) (#15361)
authorzeripath <art27@cantab.net>
Fri, 9 Apr 2021 16:45:02 +0000 (17:45 +0100)
committerGitHub <noreply@github.com>
Fri, 9 Apr 2021 16:45:02 +0000 (17:45 +0100)
Backport #15292

Simplify the web.go FCGI path by moving the req.URL.Path fix-up to listener

Signed-off-by: Andrew Thornton <art27@cantab.net>
cmd/web_graceful.go
routers/routes/web.go

index 5db065818a19f956a1c49131b38da2d4ae798a9d..91ac024ddb42f8fc12fe320fcba339c897dbaa9e 100644 (file)
@@ -9,9 +9,11 @@ import (
        "net"
        "net/http"
        "net/http/fcgi"
+       "strings"
 
        "code.gitea.io/gitea/modules/graceful"
        "code.gitea.io/gitea/modules/log"
+       "code.gitea.io/gitea/modules/setting"
 )
 
 func runHTTP(network, listenAddr, name string, m http.Handler) error {
@@ -48,7 +50,12 @@ func runFCGI(network, listenAddr, name string, m http.Handler) error {
        fcgiServer := graceful.NewServer(network, listenAddr, name)
 
        err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
-               return fcgi.Serve(listener, m)
+               return fcgi.Serve(listener, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
+                       if setting.AppSubURL != "" {
+                               req.URL.Path = strings.TrimPrefix(req.URL.Path, setting.AppSubURL)
+                       }
+                       m.ServeHTTP(resp, req)
+               }))
        })
        if err != nil {
                log.Fatal("Failed to start FCGI main server: %v", err)
index e59609d83117f45a88a1c7604934f370ba03823e..6b8d9fdb290bfd50282af8e66a6991e504f11bc2 100644 (file)
@@ -168,15 +168,6 @@ func WebRoutes() *web.Route {
                r.Use(h)
        }
 
-       if (setting.Protocol == setting.FCGI || setting.Protocol == setting.FCGIUnix) && setting.AppSubURL != "" {
-               r.Use(func(next http.Handler) http.Handler {
-                       return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
-                               req.URL.Path = strings.TrimPrefix(req.URL.Path, setting.AppSubURL)
-                               next.ServeHTTP(resp, req)
-                       })
-               })
-       }
-
        mailer.InitMailRender(templates.Mailer())
 
        if setting.Service.EnableCaptcha {