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
66import (
77 "net/http"
88 "net/url"
9+ "reflect"
910 "strings"
1011
1112 "code.gitea.io/gitea/modules/setting"
@@ -82,15 +83,23 @@ func (r *Router) getPattern(pattern string) string {
8283 return strings .TrimSuffix (newPattern , "/" )
8384}
8485
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+
8594func (r * Router ) wrapMiddlewareAndHandler (h []any ) ([]func (http.Handler ) http.Handler , http.HandlerFunc ) {
8695 handlerProviders := make ([]func (http.Handler ) http.Handler , 0 , len (r .curMiddlewares )+ len (h )+ 1 )
8796 for _ , m := range r .curMiddlewares {
88- if m != nil {
97+ if ! isNilOrFuncNil ( m ) {
8998 handlerProviders = append (handlerProviders , toHandlerProvider (m ))
9099 }
91100 }
92101 for _ , m := range h {
93- if h != nil {
102+ if ! isNilOrFuncNil ( m ) {
94103 handlerProviders = append (handlerProviders , toHandlerProvider (m ))
95104 }
96105 }
You can’t perform that action at this time.
0 commit comments