fix(waf): WebSocket 劫持后清除 http.Server 读写 deadline,避免长连接被强制断开

This commit is contained in:
qing committed 2026-08-05 00:37:11 +08:00
1 parent d71f526af4
commit 924c718005
1 file changed
+4
+4
View File
@@ -260,6 +260,10 @@ func (r *responseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
}
conn, rw, err := hijacker.Hijack()
if err == nil {
// 清除 http.Server 在劫持前设置的读写 deadline(ReadTimeout=15s / WriteTimeout=30s)。
// 这些绝对 deadline 在劫持后仍会生效,会导致长连接 WebSocket 在空闲或 30s 后被强制断开。
// 底层 WebSocket 桥接由 ReverseProxy 的 io.Copy 双向转发,长时间无人读写时应保持连接。
_ = conn.SetDeadline(time.Time{})
r.hijacked = true
// WebSocket 升级响应是 101 Switching Protocols
r.status = http.StatusSwitchingProtocols