MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / flow_entry

Method flow_entry

mitmproxy/addons/savehar.py:130–286  ·  view source on GitHub ↗

Creates HAR entry from flow

(self, flow: http.HTTPFlow, servers_seen: set[Server])

Source from the content-addressed store, hash-verified

128 self.export_har(self.flows, ctx.options.hardump)
129
130 def flow_entry(self, flow: http.HTTPFlow, servers_seen: set[Server]) -> dict:
131 """Creates HAR entry from flow"""
132
133 if flow.server_conn in servers_seen:
134 connect_time = -1.0
135 ssl_time = -1.0
136 elif flow.server_conn.timestamp_tcp_setup:
137 assert flow.server_conn.timestamp_start
138 connect_time = 1000 * (
139 flow.server_conn.timestamp_tcp_setup - flow.server_conn.timestamp_start
140 )
141
142 if flow.server_conn.timestamp_tls_setup:
143 ssl_time = 1000 * (
144 flow.server_conn.timestamp_tls_setup
145 - flow.server_conn.timestamp_tcp_setup
146 )
147 else:
148 ssl_time = -1.0
149 servers_seen.add(flow.server_conn)
150 else:
151 connect_time = -1.0
152 ssl_time = -1.0
153
154 if flow.request.timestamp_end:
155 send = 1000 * (flow.request.timestamp_end - flow.request.timestamp_start)
156 else:
157 send = 0
158
159 if flow.response and flow.request.timestamp_end:
160 wait = 1000 * (flow.response.timestamp_start - flow.request.timestamp_end)
161 else:
162 wait = 0
163
164 if flow.response and flow.response.timestamp_end:
165 receive = 1000 * (
166 flow.response.timestamp_end - flow.response.timestamp_start
167 )
168
169 else:
170 receive = 0
171
172 timings: dict[str, float | None] = {
173 "connect": connect_time,
174 "ssl": ssl_time,
175 "send": send,
176 "receive": receive,
177 "wait": wait,
178 }
179
180 if flow.response:
181 try:
182 content = flow.response.content
183 except ValueError:
184 content = flow.response.raw_content
185 response_body_size = (
186 len(flow.response.raw_content) if flow.response.raw_content else 0
187 )

Callers 5

test_seen_server_connFunction · 0.95
test_timestamp_endFunction · 0.95
test_tls_setupFunction · 0.95
test_flow_entryFunction · 0.95
make_harMethod · 0.95

Calls 8

format_multidictMethod · 0.95
valuesMethod · 0.80
addMethod · 0.45
getMethod · 0.45
decodeMethod · 0.45
get_textMethod · 0.45
appendMethod · 0.45

Tested by 4

test_seen_server_connFunction · 0.76
test_timestamp_endFunction · 0.76
test_tls_setupFunction · 0.76
test_flow_entryFunction · 0.76