Skip to content

Commit

Permalink
解决非标准的gzip压缩 (#722)
Browse files Browse the repository at this point in the history
* 解决非标准的gzip压缩

解决非标准的gzip格式
在body_encoding == gzip 时, 使用了deflate压缩, 没有使用标准的gzip压缩, 故做了兼容, 防伪未来服务端修复这个bug

* chore: remove trailing spaces

Signed-off-by: Zhanhui Li <[email protected]>

---------

Signed-off-by: Zhanhui Li <[email protected]>
Co-authored-by: Zhanhui Li <[email protected]>
  • Loading branch information
chendong0120 and lizhanhui authored Aug 6, 2024
1 parent a363f41 commit 950652b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/rocketmq/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import binascii
import gzip
import hashlib
import zlib
from typing import Dict, List

from rocketmq.definition import MessageQueue
Expand Down Expand Up @@ -184,7 +185,10 @@ def from_protobuf(cls, message, message_queue=None):
body_encoding = system_properties.body_encoding
body = raw
if body_encoding == ProtoEncoding.GZIP:
body = gzip.decompress(message.body)
if message.body and message.body[:2] == b'\x1f\x8b': # Standard Gzip format
body = gzip.decompress(message.body)
else: # deflate zip
body = zlib.decompress(message.body)
elif body_encoding in [ProtoEncoding.IDENTITY, None]:
pass
else:
Expand Down

0 comments on commit 950652b

Please sign in to comment.