Wrap capture for services used by pieces of middleware
This commit is contained in:
parent
8ca27b4a1d
commit
cf2869407d
6 changed files with 75 additions and 38 deletions
|
@ -43,9 +43,21 @@ const capturedData key = "capturedData"
|
|||
// It satisfies the alice.Constructor type.
|
||||
func Wrap(next http.Handler) (http.Handler, error) {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
c := &Capture{}
|
||||
newRW, newReq := c.renew(rw, req)
|
||||
next.ServeHTTP(newRW, newReq)
|
||||
capt, err := FromContext(req.Context())
|
||||
if err != nil {
|
||||
c := &Capture{}
|
||||
newRW, newReq := c.renew(rw, req)
|
||||
next.ServeHTTP(newRW, newReq)
|
||||
return
|
||||
}
|
||||
|
||||
if capt.NeedsReset(rw) {
|
||||
newRW, newReq := capt.renew(rw, req)
|
||||
next.ServeHTTP(newRW, newReq)
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(rw, req)
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue