-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: Allow custom io.Readers to provide a size for ContentLength in requests #6738
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Thinking
v2
An incompatible library change
Milestone
Comments
Alternatively, if http.NewRequest understood a few more std library io.Reader types, such as: - io.LimitedReader - io.SectionReader - os.File Then it wouldn't be necessary for users of the http package to create a new type to satisfy the new interface. Also the scale of the change conceptually would be smaller. |
Another very useful thing to solve this problem would by introducing a "io.SizedReader" interface, which will be satisfied by every io.Reader which additionally knows it's own size in bytes. Whether one will use the Size() method or a new ByteSize() method is open to discussion. This would also allow decompression readers to report the final size without trying to be seekable. |
Not LimitedReader. That's just a max. *os.File maybe, but that requires statting and seeking to figure out where you're at. Likewise with SectionReader, which doesn't require a stat but does require a Seek (but the seek is guaranteed to succeed). Also http://play.golang.org/p/Ee5I6oesXW makes me nervous. I'm nervous about seeking and statting, because for example: if those return an error, does NewRequest return an error (unlike Go 1.[012]), or does it silently just not set a Content-Length (surprising). Neither answer is good. Adding a new interface like interface { ContentLength() int64 } would infect or encourage infection lots of types, so that's out. Likewise with a hidden interface. Adding io.SizedReader is close to interesting, but I actually want io.SizeReaderAt (see http://talks.golang.org/2013/oscon-dl.slide#49) which I've used for a number of things inside Google. But even a * I'm inclined to do nothing. Status changed to Thinking. |
a io.Reader come from bytes.NewBuffer() or bytes.NewReader() is inefficiency when copy to a io.Writer,but the io.Reader come from http req.body(it is a io.Reader object) is efficiency.how to solve this problem?? |
I'm going to fold this into the bug about the new HTTP client: #23707 NewRequest will be changing a bunch anyway. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Thinking
v2
An incompatible library change
The text was updated successfully, but these errors were encountered: