Gzip only content related data

This commit is contained in:
Lonami Exo 2018-10-04 16:15:51 +02:00
parent 37b9922f64
commit 1b9d6aac06
2 changed files with 4 additions and 5 deletions

View File

@ -79,9 +79,9 @@ class MTProtoState:
msg_id = self._get_new_msg_id()
seq_no = self._get_seq_no(content_related)
if after_id is None:
body = GzipPacked.gzip_if_smaller(data)
body = GzipPacked.gzip_if_smaller(content_related, data)
else:
body = GzipPacked.gzip_if_smaller(
body = GzipPacked.gzip_if_smaller(content_related,
bytes(InvokeAfterMsgRequest(after_id, data)))
buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))

View File

@ -11,15 +11,14 @@ class GzipPacked(TLObject):
self.data = data
@staticmethod
def gzip_if_smaller(data):
def gzip_if_smaller(content_related, data):
"""Calls bytes(request), and based on a certain threshold,
optionally gzips the resulting data. If the gzipped data is
smaller than the original byte array, this is returned instead.
Note that this only applies to content related requests.
"""
# TODO Only content-related requests should be gzipped
if len(data) > 512:
if content_related and len(data) > 512:
gzipped = bytes(GzipPacked(data))
return gzipped if len(gzipped) < len(data) else data
else: