-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: net/http: automatically set Content-Length from Len method on Body #41182
Comments
We know that Len is the right choice for those three types. |
How about check |
@jingyugao I certainly agree that if the caller has explicitly set ContentLength then it should not be replaced. But that doesn't really address my objection. Content-Length is not a hint. It is a promise, and the code should not make a promise unless it is sure it can be kept. The code is sure for the three special-case types (which are very common). The code cannot be anywhere near as sure about any type that happens to have a Is there some widespread body implementation you are concerned about handling? |
Adding to the proposal minutes. |
In #16474 (comment), @ianlancetaylor observed:
For this case I would share Russ's concern about |
Based on the discussion above, this seems like a likely decline. |
No change in consensus, so declined. |
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?
Now in http.NewRequestWithContext
it check wether body type is a
*bytes.Buffer
,*bytes.Reader
or*strings.Reader
, then callLen()
to get content-length.What did you expect to see?
Check wether the body type implement
interfae{Len()int}
The text was updated successfully, but these errors were encountered: