-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: Setting r.Close = true in a handler does not cause the server to close the connection #70833
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
I believe this is expected behavior, but poorly worded documentation |
The docs for http.Handler explicitly state that handlers should not modify the request. I don't think we need to reducument that for every field. |
Thanks @seankhliao - the phrasing "this field is not needed by Handlers" is what threw me off here. Something to the effect of "Changing this field from Handlers has no effect" might be more helpful. |
Go version
go version go1.23.4 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Issue two requests against a handler that sets
r.Close = true
: https://go.dev/play/p/1OVTsaO82brWhat did you see happen?
Both requests used the same connection (see "Remote address" and "Close" flag on the client.)
What did you expect to see?
The server close the connection to the client per the
Request
docs:The docs do state the following:
The wording here ("not needed") implies that handlers can access it, but do not need to. In our case, we wanted to explicitly close the HTTP connection. Setting this flag did not achieve that. Setting
r.Header().Set("Connection", "close")
did.The text was updated successfully, but these errors were encountered: