Skip to content
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: clarify behavior of ResponseWriter's Write method #58518

Closed
pkositsyn opened this issue Feb 14, 2023 · 3 comments
Closed

Comments

@pkositsyn
Copy link
Contributor

The main question: is it guaranteed that Write method of http.ResponseWriter either returns non-nil error or writes all the data?

If not, then it should be encouraged to use io.Copy(rw, bytes.NewReader(...)). Somehow I'm sure, that a lot of code already relies on full writes and my proposed construction isn't elegant for such boilerplate code

If yes, I would propose to add the guarantee to the comment for Write method

I believe that the guarantee should be provided, because the alternative is unobvious and adds unnecessary boilerplate, opposed to the maintenance of the property

@gopherbot gopherbot added this to the Proposal milestone Feb 14, 2023
@seankhliao
Copy link
Member

it follows the same contract as io.Writer
no need to document it for every instance of Write

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2023
@pkositsyn
Copy link
Contributor Author

@seankhliao I mean it would be great to document it in the interface itself, not every instance of course. This should be a requirement for any implementation even

@pkositsyn
Copy link
Contributor Author

My bad, this is a guarantee of io.Writer. Sorry for wasting time

@golang golang locked and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants