mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-05 18:53:45 +08:00
fix: replace deprecated http.CloseNotifier with Request.Context().Done()
This commit is contained in:
parent
d3ffc99852
commit
26a190b5d1
@ -1327,7 +1327,7 @@ func (c *Context) SSEvent(name string, message any) {
|
|||||||
// indicates "Is client disconnected in middle of stream"
|
// indicates "Is client disconnected in middle of stream"
|
||||||
func (c *Context) Stream(step func(w io.Writer) bool) bool {
|
func (c *Context) Stream(step func(w io.Writer) bool) bool {
|
||||||
w := c.Writer
|
w := c.Writer
|
||||||
clientGone := w.CloseNotify()
|
clientGone := c.Request.Context().Done()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-clientGone:
|
case <-clientGone:
|
||||||
|
|||||||
@ -24,7 +24,6 @@ type ResponseWriter interface {
|
|||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
http.Hijacker
|
http.Hijacker
|
||||||
http.Flusher
|
http.Flusher
|
||||||
http.CloseNotifier
|
|
||||||
|
|
||||||
// Status returns the HTTP response status code of the current request.
|
// Status returns the HTTP response status code of the current request.
|
||||||
Status() int
|
Status() int
|
||||||
@ -120,11 +119,6 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|||||||
return w.ResponseWriter.(http.Hijacker).Hijack()
|
return w.ResponseWriter.(http.Hijacker).Hijack()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloseNotify implements the http.CloseNotifier interface.
|
|
||||||
func (w *responseWriter) CloseNotify() <-chan bool {
|
|
||||||
return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush implements the http.Flusher interface.
|
// Flush implements the http.Flusher interface.
|
||||||
func (w *responseWriter) Flush() {
|
func (w *responseWriter) Flush() {
|
||||||
w.WriteHeaderNow()
|
w.WriteHeaderNow()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user