summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliris <liris.pp@gmail.com>2019-12-25 21:14:33 +0900
committerGitHub <noreply@github.com>2019-12-25 21:14:33 +0900
commitbc4ab2eb791233e46e5f71b7944746bbaafc303b (patch)
tree83a629649316ac7a872465c0d29fd9888b243019
parentc1d25277f25a76c36601874ebfd7db8d24425de8 (diff)
parent79ae7ad3fd2f45724abca76fba3668c9357095b4 (diff)
downloadwebsocket-client-bc4ab2eb791233e46e5f71b7944746bbaafc303b.tar.gz
Merge pull request #576 from Mottl/compress
Show compressed text messages in wsdump.py
-rwxr-xr-xbin/wsdump.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/bin/wsdump.py b/bin/wsdump.py
index 557ace1..d16d361 100755
--- a/bin/wsdump.py
+++ b/bin/wsdump.py
@@ -6,6 +6,8 @@ import sys
import threading
import time
import ssl
+import gzip
+import zlib
import six
from six.moves.urllib.parse import urlparse
@@ -162,10 +164,24 @@ def main():
msg = None
if six.PY3 and opcode == websocket.ABNF.OPCODE_TEXT and isinstance(data, bytes):
data = str(data, "utf-8")
- if not args.verbose and opcode in OPCODE_DATA:
- msg = data
- elif args.verbose:
+ if isinstance(data, bytes) and len(data)>2 and data[:2] == b'\037\213': # gzip magick
+ try:
+ data = "[gzip] " + str(gzip.decompress(data), "utf-8")
+ except:
+ pass
+ elif isinstance(data, bytes):
+ try:
+ data = "[zlib] " + str(zlib.decompress(data, -zlib.MAX_WBITS), "utf-8")
+ except:
+ pass
+
+ if isinstance(data, bytes):
+ data = repr(data)
+
+ if args.verbose:
msg = "%s: %s" % (websocket.ABNF.OPCODE_MAP.get(opcode), data)
+ else:
+ msg = data
if msg is not None:
if args.timings: