Add text field to response content

This commit is contained in:
Shadab Zafar 2016-08-10 13:23:19 +05:30
parent 9aa230707d
commit ac97e5efa1

View File

@ -6,6 +6,7 @@ This inline script can be used to dump flows as HAR files.
import pprint import pprint
import json import json
import sys import sys
import base64
from datetime import datetime from datetime import datetime
import pytz import pytz
@ -13,6 +14,7 @@ import pytz
import mitmproxy import mitmproxy
from netlib import version from netlib import version
from netlib import strutils
from netlib.http import cookies from netlib.http import cookies
HAR = {} HAR = {}
@ -88,8 +90,8 @@ def response(flow):
started_date_time = format_datetime(datetime.utcfromtimestamp(flow.request.timestamp_start)) started_date_time = format_datetime(datetime.utcfromtimestamp(flow.request.timestamp_start))
# Size calculations # Response body size and encoding
response_body_size = len(flow.response.content) response_body_size = len(flow.response.raw_content)
response_body_decoded_size = len(flow.response.content) response_body_decoded_size = len(flow.response.content)
response_body_compression = response_body_decoded_size - response_body_size response_body_compression = response_body_decoded_size - response_body_size
@ -125,6 +127,13 @@ def response(flow):
"timings": timings, "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": if flow.request.method == "POST":
entry["request"]["postData"] = { entry["request"]["postData"] = {
"mimeType": flow.request.headers.get("Content-Type", "").split(";")[0], "mimeType": flow.request.headers.get("Content-Type", "").split(";")[0],