aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/har_dump.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py
index bdad7766..bf8c2e15 100644
--- a/examples/har_dump.py
+++ b/examples/har_dump.py
@@ -7,6 +7,7 @@ import pprint
import json
import sys
import base64
+import zlib
from datetime import datetime
import pytz
@@ -155,14 +156,16 @@ def done():
if dump_file == '-':
mitmproxy.ctx.log(pprint.pformat(HAR))
- # TODO: .zhar compression
else:
json_dump = json.dumps(HAR, indent=2)
+ if dump_file.endswith('.zhar'):
+ json_dump = zlib.compress(json_dump, 9)
+
with open(dump_file, "w") as f:
f.write(json_dump)
- mitmproxy.ctx.log("HAR log finished (wrote %s bytes to file)" % len(json_dump))
+ mitmproxy.ctx.log("HAR dump finished (wrote %s bytes to file)" % len(json_dump))
def format_datetime(dt):