File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package web
6
6
import (
7
7
"net/http"
8
8
"net/url"
9
+ "reflect"
9
10
"strings"
10
11
11
12
"code.gitea.io/gitea/modules/setting"
@@ -82,15 +83,23 @@ func (r *Router) getPattern(pattern string) string {
82
83
return strings .TrimSuffix (newPattern , "/" )
83
84
}
84
85
86
+ func isNilOrFuncNil (v any ) bool {
87
+ if v == nil {
88
+ return true
89
+ }
90
+ r := reflect .ValueOf (v )
91
+ return r .Kind () == reflect .Func && r .IsNil ()
92
+ }
93
+
85
94
func (r * Router ) wrapMiddlewareAndHandler (h []any ) ([]func (http.Handler ) http.Handler , http.HandlerFunc ) {
86
95
handlerProviders := make ([]func (http.Handler ) http.Handler , 0 , len (r .curMiddlewares )+ len (h )+ 1 )
87
96
for _ , m := range r .curMiddlewares {
88
- if m != nil {
97
+ if ! isNilOrFuncNil ( m ) {
89
98
handlerProviders = append (handlerProviders , toHandlerProvider (m ))
90
99
}
91
100
}
92
101
for _ , m := range h {
93
- if h != nil {
102
+ if ! isNilOrFuncNil ( m ) {
94
103
handlerProviders = append (handlerProviders , toHandlerProvider (m ))
95
104
}
96
105
}
You can’t perform that action at this time.
0 commit comments