iris icon indicating copy to clipboard operation
iris copied to clipboard

[BUG] accesslog: BodyMinify = true && ResponseBody = true will be change response json value

Open qkzsky opened this issue 4 years ago • 1 comments

Describe the bug accesslog: BodyMinify = true && ResponseBody = true will be change response json value

To Reproduce Steps to reproduce the behavior:

package main

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/middleware/accesslog"
)

// Read the example and its comments carefully.
func makeAccessLog() *accesslog.AccessLog {
	// Initialize a new access log middleware.
	ac := accesslog.File("./access.log")

	ac.BodyMinify = true
	ac.ResponseBody = true

	return ac
}

func main() {
	ac := makeAccessLog()
	defer ac.Close() // Close the underline file.

	app := iris.New()
	// Register the middleware (UseRouter to catch http errors too).
	app.UseRouter(ac.Handler)

	app.Get("/", indexHandler)

	app.Listen(":8080")
}

func indexHandler(ctx iris.Context) {
	ctx.JSON(map[string]int{"Num": 1000})
}

Expected behavior

{"Num": 1000}

Screenshots

{"Num": 1e30}

Desktop (please complete the following information):

  • OS: macos

iris.Version

  • v12.2.0-alpha2

Additional context Is the minify features https://github.com/tdewolff/minify/issues/386

qkzsky avatar Mar 12 '21 14:03 qkzsky

Yes, the input file to tdewolff/minify will be used as a buffer and thus gets changed. If you still need the original input file, please copy it before passing it to minify.

tdewolff avatar Mar 14 '21 16:03 tdewolff