chore: direct append data to bufio.Reader's internal buffer as much as possible

This commit is contained in:
wwqgtxx
2023-11-09 22:19:29 +08:00
parent fe7c1a2cdb
commit 832dae3421
3 changed files with 43 additions and 2 deletions

View File

@@ -554,7 +554,14 @@ func StreamUpgradedWebsocketConn(w http.ResponseWriter, r *http.Request) (net.Co
}
if edBuf := decodeXray0rtt(r.Header); len(edBuf) > 0 {
conn = N.NewCachedConn(conn, edBuf)
appendOk := false
if bufConn, ok := conn.(*N.BufferedConn); ok {
appendOk = bufConn.AppendData(edBuf)
}
if !appendOk {
conn = N.NewCachedConn(conn, edBuf)
}
}
return conn, nil