aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/tools/web/app.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py
index c0de4c1f..b7cf2c9d 100644
--- a/mitmproxy/tools/web/app.py
+++ b/mitmproxy/tools/web/app.py
@@ -17,6 +17,7 @@ from mitmproxy import http
from mitmproxy import io
from mitmproxy import log
from mitmproxy import version
+from mitmproxy.utils import strutils
def flow_to_json(flow: mitmproxy.flow.Flow) -> dict:
@@ -45,6 +46,12 @@ def flow_to_json(flow: mitmproxy.flow.Flow) -> dict:
if isinstance(flow, http.HTTPFlow):
if flow.request:
+ if flow.request.raw_content:
+ content_length = len(flow.request.raw_content)
+ content_hash = hashlib.sha256(flow.request.raw_content).hexdigest()
+ else:
+ content_length = None
+ content_hash = None
f["request"] = {
"method": flow.request.method,
"scheme": flow.request.scheme,
@@ -53,24 +60,26 @@ def flow_to_json(flow: mitmproxy.flow.Flow) -> dict:
"path": flow.request.path,
"http_version": flow.request.http_version,
"headers": tuple(flow.request.headers.items(True)),
- "contentLength": len(
- flow.request.raw_content) if flow.request.raw_content is not None else None,
- "contentHash": hashlib.sha256(
- flow.request.raw_content).hexdigest() if flow.request.raw_content is not None else None,
+ "contentLength": content_length,
+ "contentHash": content_hash,
"timestamp_start": flow.request.timestamp_start,
"timestamp_end": flow.request.timestamp_end,
"is_replay": flow.request.is_replay,
}
if flow.response:
+ if flow.response.raw_content:
+ content_length = len(flow.response.raw_content)
+ content_hash = hashlib.sha256(flow.response.raw_content).hexdigest()
+ else:
+ content_length = None
+ content_hash = None
f["response"] = {
"http_version": flow.response.http_version,
"status_code": flow.response.status_code,
"reason": flow.response.reason,
"headers": tuple(flow.response.headers.items(True)),
- "contentLength": len(
- flow.response.raw_content) if flow.response.raw_content is not None else None,
- "contentHash": hashlib.sha256(
- flow.response.raw_content).hexdigest() if flow.response.raw_content is not None else None,
+ "contentLength": content_length,
+ "contentHash": content_hash,
"timestamp_start": flow.response.timestamp_start,
"timestamp_end": flow.response.timestamp_end,
"is_replay": flow.response.is_replay,