Skip to content

Commit d2f24fa

Browse files
committed
fix an issue on accesslog when response and request recorder and minifier were enabled
1 parent 1ee6e83 commit d2f24fa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

HISTORY.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
2121

2222
# Next
2323

24-
Change applies to `master` branch.
24+
Changes apply to `master` branch.
25+
26+
- Fix [iris-premium#17](https://github.com/kataras/iris-premium/issues/17).
2527

2628
- 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).
2729

middleware/accesslog/accesslog.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -836,20 +836,27 @@ func (ac *AccessLog) after(ctx *context.Context, lat time.Duration, method, path
836836
}
837837

838838
if ac.shouldReadResponseBody() {
839-
responseData := ctx.Recorder().Body()
840-
responseBodyLength := len(responseData)
839+
actualResponseData := ctx.Recorder().Body()
840+
responseBodyLength := len(actualResponseData)
841+
841842
if ac.BytesSentBody {
842843
bytesSent = responseBodyLength
843844
}
844845
if ac.ResponseBody && responseBodyLength > 0 {
845846
if ac.BodyMinify {
847+
// Copy response data as minifier now can change the back slice,
848+
// fixes: https://github.com/kataras/iris-premium/issues/17.
849+
responseData := make([]byte, len(actualResponseData))
850+
copy(responseData, actualResponseData)
851+
846852
if minified, err := ctx.Application().Minifier().Bytes(ctx.GetContentType(), responseData); err == nil {
847853
responseBody = string(minified)
854+
responseBodyLength = len(responseBody)
848855
}
849856
}
850857

851858
if responseBody == "" {
852-
responseBody = string(responseData)
859+
responseBody = string(actualResponseData)
853860
}
854861
}
855862

0 commit comments

Comments
 (0)