This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 950652b4 解决非标准的gzip压缩 (#722)
950652b4 is described below

commit 950652b429697bd7e36f04ebdd564124079cd689
Author: kevinchen <[email protected]>
AuthorDate: Tue Aug 6 18:43:48 2024 +0800

    解决非标准的gzip压缩 (#722)
    
    * 解决非标准的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]>
---
 python/rocketmq/message.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/python/rocketmq/message.py b/python/rocketmq/message.py
index 5076da91..a315a196 100644
--- a/python/rocketmq/message.py
+++ b/python/rocketmq/message.py
@@ -17,6 +17,7 @@
 import binascii
 import gzip
 import hashlib
+import zlib
 from typing import Dict, List
 
 from rocketmq.definition import MessageQueue
@@ -184,7 +185,10 @@ class MessageView:
         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:

Reply via email to