We have an API that accepts JSON. We encourage people to gzip the payload before they POST it because we impose a limit on size. I wanted to see the actual difference in size between raw JSON and gzip'd but I can't seem to reliably and accurately get the size of the http request after it's built.
For the non-compressed version, MyJSON []byte
is the raw data before I stuff it into the http request like this:
req, err := http.NewRequest("POST", url, bytes.NewBuffer(MyJSON))
For the gzip'd version I compress the data into a buffer and then add it to the http request like this:
req, err := http.NewRequest("POST", url, &buffer)
Is it possible to get the size of the http request? And if not, I should be able to get the size of the raw MyJSON []byte
with len()
, but I can't seem to get the size of the bytes.Buffer
for the compressed version.