mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-05-31 01:35:14 +08:00
minor legibility improvements
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user