mirror of
https://github.com/nats-io/nats.go.git
synced 2025-09-26 20:41:41 +08:00
[FIXED] Protocol parsing errors with ws compression and pongs (#1790)
This commit is contained in:

committed by
GitHub

parent
f7dfee9750
commit
dfb52adad1
20
ws.go
20
ws.go
@@ -76,14 +76,15 @@ var wsGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
|
||||
var compressFinalBlock = []byte{0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff}
|
||||
|
||||
type websocketReader struct {
|
||||
r io.Reader
|
||||
pending [][]byte
|
||||
ib []byte
|
||||
ff bool
|
||||
fc bool
|
||||
nl bool
|
||||
dc *wsDecompressor
|
||||
nc *Conn
|
||||
r io.Reader
|
||||
pending [][]byte
|
||||
compress bool
|
||||
ib []byte
|
||||
ff bool
|
||||
fc bool
|
||||
nl bool
|
||||
dc *wsDecompressor
|
||||
nc *Conn
|
||||
}
|
||||
|
||||
type wsDecompressor struct {
|
||||
@@ -312,6 +313,8 @@ func (r *websocketReader) Read(p []byte) (int, error) {
|
||||
}
|
||||
r.fc = false
|
||||
}
|
||||
} else if r.compress {
|
||||
b = bytes.Clone(b)
|
||||
}
|
||||
// Add to the pending list if dealing with uncompressed frames or
|
||||
// after we have received the full compressed message and decompressed it.
|
||||
@@ -647,6 +650,7 @@ func (nc *Conn) wsInitHandshake(u *url.URL) error {
|
||||
|
||||
wsr := wsNewReader(nc.br.r)
|
||||
wsr.nc = nc
|
||||
wsr.compress = compress
|
||||
// We have to slurp whatever is in the bufio reader and copy to br.r
|
||||
if n := br.Buffered(); n != 0 {
|
||||
wsr.ib, _ = br.Peek(n)
|
||||
|
Reference in New Issue
Block a user