lxzan / gws

simple, fast, reliable websocket server & client, supports running over tcp/kcp/unix domain socket. keywords: ws, proxy, chat, go, golang...
https://pkg.go.dev/github.com/lxzan/gws
Apache License 2.0
1.34k stars 84 forks source link

contentLength and ReadMaxPayloadSize mismatch #84

Closed prawnsalad closed 4 months ago

prawnsalad commented 4 months ago

I'm trying to verify the ReadMaxPayloadSize config option but i can't quite make sense of it.

In readMessage() if I add print("contentLength = ", contentLength, " continuation? ", opcode == OpcodeContinuation, "\n") and then use this test script in Chrome:

w = new WebSocket('ws://localhost:5000/connect');
w.addEventListener('open', () => w.send('a'.repeat(1024)));

I would expect contentLength to be 1024. However, it prints contentLength = 11 continuation? false. Is there some unit mismatch or is it reading the contentLength incorrectly?

lxzan commented 4 months ago

Post the gws server configuration

prawnsalad commented 4 months ago
gws.NewUpgrader(wsHandlers, &gws.ServerOption{
        ReadAsyncEnabled: true,         // Parallel message processing
        CompressEnabled:  true,         // Enable compression
        Recovery:         gws.Recovery, // Exception recovery
        ReadMaxPayloadSize: 1024,
        Logger: lt{},
    })
lxzan commented 4 months ago

The content is compressed

prawnsalad commented 4 months ago

Ahh of course.. that makes sense! So ReadMaxPayloadSize is the protocol level max payload size. Now it makes sense and everything is good. Thank you!