fix an issue on accesslog when response and request recorder and minifier were enabled

This commit is contained in:
Gerasimos (Makis) Maropoulos 2023-04-19 23:56:55 +03:00
parent 1ee6e83ae6
commit d2f24fab90
No known key found for this signature in database
GPG Key ID: B9839E9CD30B7B6B
2 changed files with 13 additions and 4 deletions

View File

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

View File

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