http.CloseNotify是否完全被http.Request.Context()替换。完成()? [英] Is http.CloseNotify entirely replaced by http.Request.Context().Done()?

查看:455
本文介绍了http.CloseNotify是否完全被http.Request.Context()替换。完成()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将1.7添加的Context添加到http.Request。它是否完全取代了http.CloseNotify?我现在应该更喜欢这个吗,而不是打扰CloseNotify?

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?

推荐答案

是的,但仅限于Go 1.8+。这些API存在于Go 1.7中,但直到Go 1.8,客户端断开连接才导致请求的上下文完成,所以在Go 1.7中仍然有效使用CloseNotifier。

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.

(来源:我在标准库中添加了context,并且是net / http包的作者。)

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

这篇关于http.CloseNotify是否完全被http.Request.Context()替换。完成()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆