summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-04-09 14:17:57 +0100
committerGitHub <noreply@github.com>2021-04-09 21:17:57 +0800
commit9d2c251214ad49a438fff14cc6ce55477cb22414 (patch)
treeacf49147021735739693842a20ae913ffb77ce03
parent99f835b9cab8da9a14688d88228057518ca1f669 (diff)
downloadgitea-9d2c251214ad49a438fff14cc6ce55477cb22414.tar.gz
gitea-9d2c251214ad49a438fff14cc6ce55477cb22414.zip
Move FCGI req.URL.Path fix-up to the FCGI listener (#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> Co-authored-by: 6543 <6543@obermui.de>
-rw-r--r--cmd/web_graceful.go9
-rw-r--r--routers/routes/web.go9
2 files changed, 8 insertions, 10 deletions
diff --git a/cmd/web_graceful.go b/cmd/web_graceful.go
index 5db065818a..91ac024ddb 100644
--- a/cmd/web_graceful.go
+++ b/cmd/web_graceful.go
@@ -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)
diff --git a/routers/routes/web.go b/routers/routes/web.go
index b2a75acd09..7081b30e54 100644
--- a/routers/routes/web.go
+++ b/routers/routes/web.go
@@ -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 {