Decoding JSON data from HttpWriter response data that comes compressed or has extra information

54 views Asked by At

I am wrapping the RequestWriter as suggested by this answer

type MyResponseWriter struct {
    http.ResponseWriter
    buf *bytes.Buffer
}

func (mrw *MyResponseWriter) Write(p []byte) (int, error) {
    return mrw.buf.Write(p)
}

However my buffer buf becomes polluted with other encoded data which could be related to the checksums/headers @icza mentions. In longer requests I get completely unreadable data, which could be related with compression. How can can you deal with this data if you want to parse it into a json for logging purposes for example?

Here are a couple of snapshots of what I get if I try to log buf.String()

longer json

shorter json

0

There are 0 answers