-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: check for http.ResponseWriter WriteHeader calls after body has been written #27668
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
Comments
@adamdecaf this new vet logic would need to ignore the case where trailers are being set? |
/cc @alandonovan @josharian @mvdan per owners. Also /cc @dominikh in case this is one of the checks you've considered previously for staticcheck. |
I quickly prototyped this using the approach of the nilness checker, looking for a call to w.Header().Set() dominated by a conversion of w to io.Writer. You could go further by identifying other functions that "may write to w" while it is still a ResponseWriter.
I've attached the log of what it found in the standard library--all tests, unsurprisingly. BTW: I hope you wrote |
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
)?What did you do?
Consider the following code:
This code outputs:
Comments
It would be nice for vet to be aware of this common mistake and be able to alert the developer to an easy fix. The documentation for
http.ResponseWriter
describes all the details, but that's often missed.The text was updated successfully, but these errors were encountered: