From 032942a466939f6bb291677495c97bac8a737253 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 10 Dec 2018 18:45:20 -0300 Subject: [PATCH] gateway.websocket: prevent empty messages on zlib-stream --- litecord/gateway/websocket.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/litecord/gateway/websocket.py b/litecord/gateway/websocket.py index 500a9c1..908c88f 100644 --- a/litecord/gateway/websocket.py +++ b/litecord/gateway/websocket.py @@ -164,6 +164,15 @@ class GatewayWebsocket: log.debug('zlib-stream: length {} -> compressed ({} + {})', len(encoded), len(data1), len(data2)) + if not data1: + # if data1 is nothing, that might cause problems + # to clients, since they'll receive an empty message + data1 = bytes([data2[0]]) + data2 = data2[1:] + + log.debug('zlib-stream: len(data1) == 0, remaking as ({} + {})', + len(data1), len(data2)) + # NOTE: the old approach was ws.send(data1 + data2). # I changed this to a chunked send of data1 and data2 # because that can bring some problems to the network