Is http.CloseNotify entirely replaced by http.Requ

2019-06-16 17:34发布

Go 1.7 added Context to the http.Request. Does it completely replace http.CloseNotify? Should I prefer that now, and not bother with CloseNotify?

标签: http go
1条回答
Rolldiameter
2楼-- · 2019-06-16 17:55

Yes, but only in Go 1.8+. The APIs existed in Go 1.7 but it wasn't until Go 1.8 that the client's disconnection caused the Request's Context to be Done, so in Go 1.7 there was still a valid use of CloseNotifier.

(Source: I added "context" to the standard library and am the author of the net/http package.)

查看更多
登录 后发表回答