Skip to content

Commit 9d2c251

Browse files
zeripath6543
andauthored
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 <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 99f835b commit 9d2c251

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

cmd/web_graceful.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"net"
1010
"net/http"
1111
"net/http/fcgi"
12+
"strings"
1213

1314
"code.gitea.io/gitea/modules/graceful"
1415
"code.gitea.io/gitea/modules/log"
16+
"code.gitea.io/gitea/modules/setting"
1517
)
1618

1719
func runHTTP(network, listenAddr, name string, m http.Handler) error {
@@ -48,7 +50,12 @@ func runFCGI(network, listenAddr, name string, m http.Handler) error {
4850
fcgiServer := graceful.NewServer(network, listenAddr, name)
4951

5052
err := fcgiServer.ListenAndServe(func(listener net.Listener) error {
51-
return fcgi.Serve(listener, m)
53+
return fcgi.Serve(listener, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
54+
if setting.AppSubURL != "" {
55+
req.URL.Path = strings.TrimPrefix(req.URL.Path, setting.AppSubURL)
56+
}
57+
m.ServeHTTP(resp, req)
58+
}))
5259
})
5360
if err != nil {
5461
log.Fatal("Failed to start FCGI main server: %v", err)

routers/routes/web.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ func WebRoutes() *web.Route {
168168
r.Use(h)
169169
}
170170

171-
if (setting.Protocol == setting.FCGI || setting.Protocol == setting.FCGIUnix) && setting.AppSubURL != "" {
172-
r.Use(func(next http.Handler) http.Handler {
173-
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
174-
req.URL.Path = strings.TrimPrefix(req.URL.Path, setting.AppSubURL)
175-
next.ServeHTTP(resp, req)
176-
})
177-
})
178-
}
179-
180171
mailer.InitMailRender(templates.Mailer())
181172

182173
if setting.Service.EnableCaptcha {

0 commit comments

Comments
 (0)