From 412c0112d933422bb1e07da5dc70470fa2704383 Mon Sep 17 00:00:00 2001 From: dillonstreator Date: Tue, 21 Nov 2023 13:08:28 -0600 Subject: [PATCH] defer f --- hlog/hlog.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hlog/hlog.go b/hlog/hlog.go index b436593b..c3750507 100644 --- a/hlog/hlog.go +++ b/hlog/hlog.go @@ -343,14 +343,16 @@ func AccessHandlerWithData(f func(data AccessHandlerData)) func(next http.Handle body := mutil.NewByteCountReadCloser(r.Body) r.Body = body + defer func() { + f(AccessHandlerData{ + Request: r, + Duration: time.Since(start), + Status: ww.Status(), + BytesWritten: ww.BytesWritten(), + BytesRead: body.BytesRead(), + }) + }() next.ServeHTTP(ww, r) - f(AccessHandlerData{ - Request: r, - Duration: time.Since(start), - Status: ww.Status(), - BytesWritten: ww.BytesWritten(), - BytesRead: body.BytesRead(), - }) }) } }