httplog icon indicating copy to clipboard operation
httplog copied to clipboard

Logging compressed response

Open benja8151 opened this issue 1 year ago • 0 comments

Using httplog in combination with chi compress middleware logs compressed response body. Has anyone encountered similar issues before? I wrote a custom implementation of httplog where I manually decompress response, but I'm wondering if there is a cleaner solution?

To reproduce, add compress middleware to example and set Content-Type header to text/plain:

// main.go, 24-27
r.Use(httplog.RequestLogger(logger, []string{"/ping"}))
r.Use(middleware.Compress(5))
r.Use(middleware.SetHeader("Content-Type", "text/plain"))
r.Use(middleware.Heartbeat("/ping"))

Example of console output when calling /warn endpoint with JSON: false and Concise: false: image where you can see response body logged as "\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000�*O,�S�H-J\u0005\u0004\u0000\u0000��?�\u001dv\t\u0000\u0000\u0000"

benja8151 avatar Apr 20 '23 07:04 benja8151