From 14205a0b2e50a04ecacfb4f7703c630b4fdc513d Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 5 May 2018 23:53:00 +0200 Subject: [PATCH] fix message length --- ws/message.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ws/message.go b/ws/message.go index 8ca95ea..e577eb7 100644 --- a/ws/message.go +++ b/ws/message.go @@ -153,6 +153,11 @@ func (m Message) Send(socket net.Conn) error { header := make([]byte, 0, maximumHeaderSize) + // fix size + if uint(len(m.Data)) <= m.Size { + m.Size = uint( len(m.Data) ) + } + /* (1) Byte 0 : FIN + opcode */ header = append(header, 0x80 | byte(TEXT) ) @@ -182,7 +187,7 @@ func (m Message) Send(socket net.Conn) error { /* (3) Build write buffer */ writeBuf := make([]byte, 0, len(header) + int(m.Size)) writeBuf = append(writeBuf, header...) - writeBuf = append(writeBuf, m.Data...) + writeBuf = append(writeBuf, m.Data[0:m.Size]...) /* (4) Send over socket */ _, err := socket.Write(writeBuf)