diff --git a/HISTORY.md b/HISTORY.md index a5208b96..9203a137 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -21,7 +21,9 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene # Next -Change applies to `master` branch. +Changes apply to `master` branch. + +- Fix [iris-premium#17](https://github.com/kataras/iris-premium/issues/17). - Replace [russross/blackfriday](github.com/russross/blackfriday/v2) with [gomarkdown](https://github.com/gomarkdown/markdown) as requested at [#2098](https://github.com/kataras/iris/issues/2098). diff --git a/middleware/accesslog/accesslog.go b/middleware/accesslog/accesslog.go index 1320718c..155f58c4 100644 --- a/middleware/accesslog/accesslog.go +++ b/middleware/accesslog/accesslog.go @@ -836,20 +836,27 @@ func (ac *AccessLog) after(ctx *context.Context, lat time.Duration, method, path } if ac.shouldReadResponseBody() { - responseData := ctx.Recorder().Body() - responseBodyLength := len(responseData) + actualResponseData := ctx.Recorder().Body() + responseBodyLength := len(actualResponseData) + if ac.BytesSentBody { bytesSent = responseBodyLength } if ac.ResponseBody && responseBodyLength > 0 { if ac.BodyMinify { + // Copy response data as minifier now can change the back slice, + // fixes: https://github.com/kataras/iris-premium/issues/17. + responseData := make([]byte, len(actualResponseData)) + copy(responseData, actualResponseData) + if minified, err := ctx.Application().Minifier().Bytes(ctx.GetContentType(), responseData); err == nil { responseBody = string(minified) + responseBodyLength = len(responseBody) } } if responseBody == "" { - responseBody = string(responseData) + responseBody = string(actualResponseData) } }