diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-10 13:23:19 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-15 12:00:23 +0530 |
commit | ac97e5efa1f87f67fe1ac7e1b61be5f374edd65f (patch) | |
tree | 084c93ab4289be67951e3285ea2c50aea9419fc3 /examples | |
parent | 9aa230707d4868d02df2cdc47abf4bbbcab40ba8 (diff) | |
download | mitmproxy-ac97e5efa1f87f67fe1ac7e1b61be5f374edd65f.tar.gz mitmproxy-ac97e5efa1f87f67fe1ac7e1b61be5f374edd65f.tar.bz2 mitmproxy-ac97e5efa1f87f67fe1ac7e1b61be5f374edd65f.zip |
Add text field to response content
Diffstat (limited to 'examples')
-rw-r--r-- | examples/har_dump.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py index 6903608d..bdad7766 100644 --- a/examples/har_dump.py +++ b/examples/har_dump.py @@ -6,6 +6,7 @@ This inline script can be used to dump flows as HAR files. import pprint import json import sys +import base64 from datetime import datetime import pytz @@ -13,6 +14,7 @@ import pytz import mitmproxy from netlib import version +from netlib import strutils from netlib.http import cookies HAR = {} @@ -88,8 +90,8 @@ def response(flow): started_date_time = format_datetime(datetime.utcfromtimestamp(flow.request.timestamp_start)) - # Size calculations - response_body_size = len(flow.response.content) + # Response body size and encoding + response_body_size = len(flow.response.raw_content) response_body_decoded_size = len(flow.response.content) response_body_compression = response_body_decoded_size - response_body_size @@ -125,6 +127,13 @@ def response(flow): "timings": timings, } + # Store binay data as base64 + if strutils.is_mostly_bin(flow.response.content): + entry["response"]["content"]["text"] = base64.b64encode(flow.response.content) + entry["response"]["content"]["encoding"] = "base64" + else: + entry["response"]["content"]["text"] = flow.response.content + if flow.request.method == "POST": entry["request"]["postData"] = { "mimeType": flow.request.headers.get("Content-Type", "").split(";")[0], |