MCPcopy
hub / github.com/mitmproxy/mitmproxy / flow_to_json

Function flow_to_json

mitmproxy/tools/web/app.py:82–209  ·  view source on GitHub ↗

Remove flow message content and cert to save transmission space. Args: flow: The original flow. Sync with web/src/flow.ts.

(flow: mitmproxy.flow.Flow)

Source from the content-addressed store, hash-verified

80
81
82def flow_to_json(flow: mitmproxy.flow.Flow) -> dict:
83 """
84 Remove flow message content and cert to save transmission space.
85 Args:
86 flow: The original flow.
87 Sync with web/src/flow.ts.
88 """
89 f = {
90 "id": flow.id,
91 "intercepted": flow.intercepted,
92 "is_replay": flow.is_replay,
93 "type": flow.type,
94 "modified": flow.modified(),
95 "marked": emoji.get(flow.marked, "🔴") if flow.marked else "",
96 "comment": flow.comment,
97 "timestamp_created": flow.timestamp_created,
98 }
99
100 if flow.client_conn:
101 f["client_conn"] = {
102 "id": flow.client_conn.id,
103 "peername": flow.client_conn.peername,
104 "sockname": flow.client_conn.sockname,
105 "tls_established": flow.client_conn.tls_established,
106 "cert": cert_to_json(flow.client_conn.certificate_list),
107 "sni": flow.client_conn.sni,
108 "cipher": flow.client_conn.cipher,
109 "alpn": always_str(flow.client_conn.alpn, "ascii", "backslashreplace"),
110 "tls_version": flow.client_conn.tls_version,
111 "timestamp_start": flow.client_conn.timestamp_start,
112 "timestamp_tls_setup": flow.client_conn.timestamp_tls_setup,
113 "timestamp_end": flow.client_conn.timestamp_end,
114 }
115
116 if flow.server_conn:
117 f["server_conn"] = {
118 "id": flow.server_conn.id,
119 "peername": flow.server_conn.peername,
120 "sockname": flow.server_conn.sockname,
121 "address": flow.server_conn.address,
122 "tls_established": flow.server_conn.tls_established,
123 "cert": cert_to_json(flow.server_conn.certificate_list),
124 "sni": flow.server_conn.sni,
125 "cipher": flow.server_conn.cipher,
126 "alpn": always_str(flow.server_conn.alpn, "ascii", "backslashreplace"),
127 "tls_version": flow.server_conn.tls_version,
128 "timestamp_start": flow.server_conn.timestamp_start,
129 "timestamp_tcp_setup": flow.server_conn.timestamp_tcp_setup,
130 "timestamp_tls_setup": flow.server_conn.timestamp_tls_setup,
131 "timestamp_end": flow.server_conn.timestamp_end,
132 }
133 if flow.error:
134 f["error"] = flow.error.get_state()
135
136 if isinstance(flow, HTTPFlow):
137 content_length: int | None
138 content_hash: str | None
139

Callers 5

test_save_flowsFunction · 0.90
file_to_flowsFunction · 0.90
save_flowsFunction · 0.90
broadcast_flowMethod · 0.85
getMethod · 0.85

Calls 7

always_strFunction · 0.90
cert_to_jsonFunction · 0.85
modifiedMethod · 0.80
getMethod · 0.45
get_stateMethod · 0.45
itemsMethod · 0.45
to_jsonMethod · 0.45

Tested by 2

test_save_flowsFunction · 0.72
file_to_flowsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…