Skip to content

Commit

Permalink
websocket: fix protocol message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Jul 16, 2024
1 parent ebb0bdb commit a7eb6fb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nbhttp/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func (c *Conn) Parse(data []byte) error {
var message []byte
var msgType MessageType
var protocolMessage []byte
var isProtocolMessage bool
var opcode MessageType
var ok, fin, compress bool
var totalFrameSize int
Expand Down Expand Up @@ -448,6 +449,7 @@ func (c *Conn) Parse(data []byte) error {
}
}
case PingMessage, PongMessage, CloseMessage:
isProtocolMessage = true
if bl > 0 {
protocolMessage = allocator.Malloc(len(body))
copy(protocolMessage, body)
Expand Down Expand Up @@ -482,9 +484,10 @@ func (c *Conn) Parse(data []byte) error {
c.handleDataFrame(msgType, fin, frame)
frame = nil
}
if fin && opcode == CloseMessage { //protocolMessage != nil {
if isProtocolMessage {
c.handleProtocolMessage(opcode, protocolMessage)
protocolMessage = nil
isProtocolMessage = false
}

// need more data
Expand Down

0 comments on commit a7eb6fb

Please sign in to comment.