diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-01-06 01:01:05 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-01-07 23:08:50 +0100 |
commit | c41bd3fafda2f62299218b4d1eb5ef964f7f3aa9 (patch) | |
tree | 37c4975e8891147ce4819deb3763ff2ad8c649e3 | |
parent | b1ec7e78cdb3bb0432667d7a029cfe00f07a3b11 (diff) | |
download | mitmproxy-c41bd3fafda2f62299218b4d1eb5ef964f7f3aa9.tar.gz mitmproxy-c41bd3fafda2f62299218b4d1eb5ef964f7f3aa9.tar.bz2 mitmproxy-c41bd3fafda2f62299218b4d1eb5ef964f7f3aa9.zip |
minor legibility improvements
-rw-r--r-- | mitmproxy/tools/web/app.py | 25 |
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, |