diff --git a/ws/client.go b/ws/client.go index 999555b..7a42604 100644 --- a/ws/client.go +++ b/ws/client.go @@ -156,12 +156,14 @@ func clientReader(c *client){ /* (4) CLOSE */ if msg.Type == CLOSE { - // fmt.Printf(" [reader] CLOSE ; size %d\n", msg.Size) - // if msg.Size >= 2 { - // errCode := binary.BigEndian.Uint16(msg.Data[0:2]) - // fmt.Printf(" ; status %d\n", errCode) - // fmt.Printf(" ; msg '%s'\n", msg.Data[2:]) - // } + // uncomplete code || too long + if msg.Size == 1 || msg.Size > 125 { + errorCode = PROTOCOL_ERR + } + // invalid utf-8 reason + if msg.Size > 2 && !utf8.Valid(msg.Data[2:]) { + errorCode = INVALID_PAYLOAD + } clientAck = false break