net/http: populate Uncompressed Content-Length #38928
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Currently when the
net/http
package receives a compressed response, theContentLength
is set to -1 and removed from the Header array:https://golang.org/pkg/net/http/#Response (See field
Uncompressed
)Often we are not interested in the body but only the
Content-Length
. If that's the case we often doio.Copy(ioutil.Discard, resp.Body)
to consume the body.Without checking the body length or the return from
ioutil.Discard
it's not possible to get the uncompressedContent-Length
from the Response.What did you expect to see?
I would suggest to introduce a new Property in the
Response
likeUncompressedContentLength
to make the uncompressed size available to the caller before the body is read. At this stage the size should already be known to go, as theUncompressed
property has already been processed.What did you see instead?
The text was updated successfully, but these errors were encountered: