gateway.websocket: prevent empty messages on zlib-stream

This commit is contained in:
Luna 2018-12-10 18:45:20 -03:00
parent 6872139ff6
commit 032942a466
1 changed files with 9 additions and 0 deletions

View File

@ -164,6 +164,15 @@ class GatewayWebsocket:
log.debug('zlib-stream: length {} -> compressed ({} + {})', log.debug('zlib-stream: length {} -> compressed ({} + {})',
len(encoded), len(data1), len(data2)) 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). # NOTE: the old approach was ws.send(data1 + data2).
# I changed this to a chunked send of data1 and data2 # I changed this to a chunked send of data1 and data2
# because that can bring some problems to the network # because that can bring some problems to the network