Browse Source

Fix bug in Wrap (#15302) (#15309)

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>
Co-authored-by: zeripath <art27@cantab.net>
mj-v1.14.3
6543 1 year ago
committed by GitHub
parent
commit
a8c6a4a70e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      modules/web/route.go

7
modules/web/route.go

@ -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))
}

Loading…
Cancel
Save