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

net/http: Send 410 Gone client error with http.Error() #24530

qboot opened this issue Mar 26, 2018 · 2 comments


None yet
3 participants
Copy link

commented Mar 26, 2018


First, thanks for all your work, it's amazing.

I'm trying to properly send a 410 Gone response with the net/http package.

I would like to do something like this http.Error(w, "", http.StatusGone).

But after reading the http.Error() function code here we can see that the error response is written with fmt.Fprintln() which add a new line at the end and make the Content-Length header to be 1 instead of 0.

Is there a particular reason here to not just use fmt.Fprint() ?

For now, I simply use:

fmt.Fprint(w, "")

But it would be cleaner if I can just call the http.Error() which seems to be intended for this purpose.


This comment has been minimized.

Copy link

commented Mar 26, 2018

I think that would be considered a breaking change. Unit tests will start to fail and clients expecting a newline at the end will break.

If you are concerned about the Content-Length header, no need to even make the fmt.Fprint call. Just do a WriteHeader and return.


This comment has been minimized.

Copy link

commented Mar 26, 2018

Thanks @agnivade for the explanation 👍.
Indeed WriteHeader then return is sufficient for my concern.

@qboot qboot closed this Mar 26, 2018

@golang golang locked and limited conversation to collaborators Mar 26, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.