@@ -6,11 +6,9 @@ package web
6
6
7
7
import (
8
8
"encoding/gob"
9
- "fmt"
10
9
"net/http"
11
10
"os"
12
11
"path"
13
- "strings"
14
12
15
13
"code.gitea.io/gitea/models"
16
14
"code.gitea.io/gitea/modules/context"
@@ -45,7 +43,6 @@ import (
45
43
"gitea.com/go-chi/captcha"
46
44
"gitea.com/go-chi/session"
47
45
"github.com/NYTimes/gziphandler"
48
- "github.com/chi-middleware/proxy"
49
46
"github.com/go-chi/chi/middleware"
50
47
"github.com/go-chi/cors"
51
48
"github.com/prometheus/client_golang/prometheus"
@@ -57,63 +54,6 @@ const (
57
54
GzipMinSize = 1400
58
55
)
59
56
60
- func commonMiddlewares () []func (http.Handler ) http.Handler {
61
- var handlers = []func (http.Handler ) http.Handler {
62
- func (next http.Handler ) http.Handler {
63
- return http .HandlerFunc (func (resp http.ResponseWriter , req * http.Request ) {
64
- next .ServeHTTP (context .NewResponse (resp ), req )
65
- })
66
- },
67
- }
68
-
69
- if setting .ReverseProxyLimit > 0 {
70
- opt := proxy .NewForwardedHeadersOptions ().
71
- WithForwardLimit (setting .ReverseProxyLimit ).
72
- ClearTrustedProxies ()
73
- for _ , n := range setting .ReverseProxyTrustedProxies {
74
- if ! strings .Contains (n , "/" ) {
75
- opt .AddTrustedProxy (n )
76
- } else {
77
- opt .AddTrustedNetwork (n )
78
- }
79
- }
80
- handlers = append (handlers , proxy .ForwardedHeaders (opt ))
81
- }
82
-
83
- handlers = append (handlers , middleware .StripSlashes )
84
-
85
- if ! setting .DisableRouterLog && setting .RouterLogLevel != log .NONE {
86
- if log .GetLogger ("router" ).GetLevel () <= setting .RouterLogLevel {
87
- handlers = append (handlers , LoggerHandler (setting .RouterLogLevel ))
88
- }
89
- }
90
- if setting .EnableAccessLog {
91
- handlers = append (handlers , context .AccessLogger ())
92
- }
93
-
94
- handlers = append (handlers , func (next http.Handler ) http.Handler {
95
- return http .HandlerFunc (func (resp http.ResponseWriter , req * http.Request ) {
96
- // Why we need this? The Recovery() will try to render a beautiful
97
- // error page for user, but the process can still panic again, and other
98
- // middleware like session also may panic then we have to recover twice
99
- // and send a simple error page that should not panic any more.
100
- defer func () {
101
- if err := recover (); err != nil {
102
- combinedErr := fmt .Sprintf ("PANIC: %v\n %s" , err , string (log .Stack (2 )))
103
- log .Error ("%v" , combinedErr )
104
- if setting .IsProd () {
105
- http .Error (resp , http .StatusText (500 ), 500 )
106
- } else {
107
- http .Error (resp , combinedErr , 500 )
108
- }
109
- }
110
- }()
111
- next .ServeHTTP (resp , req )
112
- })
113
- })
114
- return handlers
115
- }
116
-
117
57
var corsHandler func (http.Handler ) http.Handler
118
58
119
59
// NormalRoutes represents non install routes
0 commit comments