mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
websockets set max payload log size. (#42)
This commit is contained in:
parent
2ff47ac920
commit
43a649d2c4
@ -23,6 +23,9 @@ const pingPeriod = 10 * time.Second
|
|||||||
// period for sending inactive cursor messages
|
// period for sending inactive cursor messages
|
||||||
const inactiveCursorsPeriod = 750 * time.Millisecond
|
const inactiveCursorsPeriod = 750 * time.Millisecond
|
||||||
|
|
||||||
|
// maximum payload length for logging
|
||||||
|
const maxPayloadLogLength = 10_000
|
||||||
|
|
||||||
// events that are not logged in debug mode
|
// events that are not logged in debug mode
|
||||||
var nologEvents = []string{
|
var nologEvents = []string{
|
||||||
// don't log twice
|
// don't log twice
|
||||||
@ -313,10 +316,15 @@ func (manager *WebSocketManagerCtx) handle(connection *websocket.Conn, peer type
|
|||||||
|
|
||||||
// log events if not ignored
|
// log events if not ignored
|
||||||
if ok, _ := utils.ArrayIn(data.Event, nologEvents); !ok {
|
if ok, _ := utils.ArrayIn(data.Event, nologEvents); !ok {
|
||||||
|
payload := data.Payload
|
||||||
|
if len(payload) > maxPayloadLogLength {
|
||||||
|
payload = []byte("<truncated>")
|
||||||
|
}
|
||||||
|
|
||||||
logger.Debug().
|
logger.Debug().
|
||||||
Str("address", connection.RemoteAddr().String()).
|
Str("address", connection.RemoteAddr().String()).
|
||||||
Str("event", data.Event).
|
Str("event", data.Event).
|
||||||
Str("payload", string(data.Payload)).
|
Str("payload", string(payload)).
|
||||||
Msg("received message from client")
|
Msg("received message from client")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/demodesk/neko/pkg/types"
|
"github.com/demodesk/neko/pkg/types"
|
||||||
"github.com/demodesk/neko/pkg/types/event"
|
"github.com/demodesk/neko/pkg/types/event"
|
||||||
"github.com/demodesk/neko/pkg/types/message"
|
"github.com/demodesk/neko/pkg/types/message"
|
||||||
|
"github.com/demodesk/neko/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebSocketPeerCtx struct {
|
type WebSocketPeerCtx struct {
|
||||||
@ -60,11 +61,18 @@ func (peer *WebSocketPeerCtx) Send(event string, payload any) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log events if not ignored
|
||||||
|
if ok, _ := utils.ArrayIn(event, nologEvents); !ok {
|
||||||
|
if len(raw) > maxPayloadLogLength {
|
||||||
|
raw = []byte("<truncated>")
|
||||||
|
}
|
||||||
|
|
||||||
peer.logger.Debug().
|
peer.logger.Debug().
|
||||||
Str("address", peer.connection.RemoteAddr().String()).
|
Str("address", peer.connection.RemoteAddr().String()).
|
||||||
Str("event", event).
|
Str("event", event).
|
||||||
Str("payload", string(raw)).
|
Str("payload", string(raw)).
|
||||||
Msg("sending message to client")
|
Msg("sending message to client")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *WebSocketPeerCtx) Ping() error {
|
func (peer *WebSocketPeerCtx) Ping() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user