http - Golang - 劫持参数

标签 http go go-http

使用 Hijack() 时使用 http.ResponseWriter 实例

Hijack() (net.Conn, *bufio.ReadWriter, error)

net.Conn读取和从*bufio.ReadWriter读取有什么区别?

最佳答案

net.Conn.Read*bufio.ReadWriter.Read 都从同一个连接读取,但后者是缓冲的。标准“net/http”包中的Hijack方法直接返回包裹在bufio.ReadWriter中的net.Conn,使用相同的*bufio.Reader 已经为 http 请求分配了。

bufio.Reader 中可能仍有缓冲的数据,您在直接从网络连接读取时可能会错过这些数据。如果你想直接使用net.Conn,你应该用Reader.Buffered检查是否有缓冲数据。 ,并根据正在使用的协议(protocol)进行处理。

一般来说,您应该更喜欢使用 bufio.ReadWriter,因为对于非最佳大小的网络读取和写入,它会更有效。

net.Conn 仍然需要处理读取和写入的截止时间,完成后关闭 net.Conn,对于任何其他网络-具体事件。

关于http - Golang - 劫持参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35562820/

相关文章:

http - 在发送响应之前测量 goodput

rest - 发布不存在的 ID 时,REST API 是否应该返回 404?

http - 如何在nifi中使用invoke http来执行GET请求?

http - Golang http客户端为什么有MaxConnsPerHost没有MaxConns

go - tls : no renegotiation error on HTTP request

mysql - 不支持扫描,将 driver.Value 类型 []uint8 存储到 *time.Time 类型中

go-mail 嵌入图像不适用于 exe

go - 如何在最新的 Go 周刊中比较两个函数的指针相等性?

go - "http.FileServer(http.Dir...))"不能在单独的包中工作

go - web.Request 结构的字段状态未在 Golang 中正确克隆