Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is http.CloseNotify entirely replaced by http.Request.Context().Done()?

Tags:

http

go

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?

like image 777
Matt Joiner Avatar asked May 22 '17 08:05

Matt Joiner


1 Answers

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.)

like image 120
Brad Fitzpatrick Avatar answered Oct 22 '22 22:10

Brad Fitzpatrick