Skip to content

Commit

Permalink
Set read limit to 16 KB
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
  • Loading branch information
gabriel-samfira committed Jul 5, 2024
1 parent a2c606b commit 49f1b7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
pingPeriod = (pongWait * 9) / 10

// Maximum message size allowed from peer.
maxMessageSize = 1024
maxMessageSize = 16384 // 16 KB
)

type HandleWebsocketMessage func([]byte) error
Expand Down
3 changes: 3 additions & 0 deletions websocket/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ func (w *Reader) Start() error {

func (w *Reader) printWebsocketToConsole() {
defer w.Stop()
w.writeMux.Lock()
w.conn.SetReadLimit(maxMessageSize)
w.conn.SetReadDeadline(time.Now().Add(pongWait))
w.conn.SetPongHandler(func(string) error { w.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
w.writeMux.Unlock()
for {
_, message, err := w.conn.ReadMessage()
if err != nil {
Expand Down

0 comments on commit 49f1b7a

Please sign in to comment.