vegeta icon indicating copy to clipboard operation
vegeta copied to clipboard

Proposal: Use content-length header instead of body for bytes in

Open Teddy-Schmitz opened this issue 5 years ago • 2 comments

Proposal

Use response.ContentLength in determining the number bytes in of a response rather then len(response.Body)

Background

I noticed that my bytes in was zero if I set the body limit to 0. I don't want to read in the body but I do want to know the size of it. To preserve previous behaviour we could do this only if MaxBody is set.

Workarounds

Don't use the MaxBody option

Teddy-Schmitz avatar Mar 27 '19 11:03 Teddy-Schmitz

This would not work if the server sends data in chunked encoding, but in that case, it should be set to -1 as per documentation:

        // ContentLength records the length of the associated content. The
        // value -1 indicates that the length is unknown. Unless Request.Method
        // is "HEAD", values >= 0 indicate that the given number of bytes may
        // be read from Body.
        ContentLength int64

PR welcome.

tsenart avatar Mar 27 '19 11:03 tsenart

Great thanks, PR #384 ready for review

Teddy-Schmitz avatar Mar 27 '19 15:03 Teddy-Schmitz