From 567cbe6cb9bae3bde7b1d4d95ad70dd0db3485ff Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Wed, 10 Aug 2016 13:41:48 +0530 Subject: Support .zhar compression --- examples/har_dump.py | 7 +++++-- 1 file 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): -- cgit v1.2.3