]> source.dussan.org Git - gitea.git/commitdiff
Fix bug in Wrap (#15302)
authorzeripath <art27@cantab.net>
Tue, 6 Apr 2021 15:40:56 +0000 (16:40 +0100)
committerGitHub <noreply@github.com>
Tue, 6 Apr 2021 15:40:56 +0000 (17:40 +0200)
Whilst doing other work I have noticed that there is an issue with Wrap when passing an
http.Handler - the next should be the next handler in line not empty.

Signed-off-by: Andrew Thornton <art27@cantab.net>
modules/web/route.go

index 59e22c5be15f75b145f0ca382aceb208ce6d5df5..6f9e76bdf389090b80533e5f9dfdc78192a60e07 100644 (file)
@@ -68,10 +68,11 @@ func Wrap(handlers ...interface{}) http.HandlerFunc {
                                }
                        case func(http.Handler) http.Handler:
                                var next = http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
-                               t(next).ServeHTTP(resp, req)
-                               if r, ok := resp.(context.ResponseWriter); ok && r.Status() > 0 {
-                                       return
+                               if len(handlers) > i+1 {
+                                       next = Wrap(handlers[i+1:]...)
                                }
+                               t(next).ServeHTTP(resp, req)
+                               return
                        default:
                                panic(fmt.Sprintf("Unsupported handler type: %#v", t))
                        }