mirror of https://gitlab.com/litecord/litecord.git
gateway.websocket: ignore compression when encoding=etf
This commit is contained in:
parent
6c802ad3fa
commit
c8d37019a9
|
|
@ -173,25 +173,23 @@ class GatewayWebsocket:
|
||||||
payload.get("t"),
|
payload.get("t"),
|
||||||
)
|
)
|
||||||
|
|
||||||
# treat encoded as bytes
|
if isinstance(encoded, str):
|
||||||
if not isinstance(encoded, bytes):
|
|
||||||
encoded = encoded.encode()
|
encoded = encoded.encode()
|
||||||
|
|
||||||
if self.wsp.compress == "zlib-stream":
|
if self.wsp.compress == "zlib-stream":
|
||||||
await self._zlib_stream_send(encoded)
|
await self._zlib_stream_send(encoded)
|
||||||
elif self.wsp.compress == "zstd-stream":
|
elif self.wsp.compress == "zstd-stream":
|
||||||
await self._zstd_stream_send(encoded)
|
await self._zstd_stream_send(encoded)
|
||||||
elif self.state and self.state.compress and len(encoded) > 1024:
|
elif (
|
||||||
# TODO: should we only compress on >1KB packets? or maybe we
|
self.state
|
||||||
# should do all?
|
and self.state.compress
|
||||||
|
and len(encoded) > 8192
|
||||||
|
and self.wsp.encoding != "etf"
|
||||||
|
):
|
||||||
|
# TODO determine better conditions to trigger a compress set
|
||||||
|
# by identify
|
||||||
await self.ws.send(zlib.compress(encoded))
|
await self.ws.send(zlib.compress(encoded))
|
||||||
else:
|
else:
|
||||||
try:
|
|
||||||
# assume encoded is string, json based, decoding it
|
|
||||||
# should give reasonable messages down the websocket
|
|
||||||
await self.ws.send(encoded.decode())
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
# in here, encoded is ETF, its bytes(), so we send it raw
|
|
||||||
await self.ws.send(encoded)
|
await self.ws.send(encoded)
|
||||||
|
|
||||||
async def send_op(self, op_code: int, data: Any):
|
async def send_op(self, op_code: int, data: Any):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue