aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-08-09 11:05:16 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-08-15 12:00:23 +0530
commitb14eb57db190ae08266d96dbadc2458595914518 (patch)
tree3bf1bd8e3952136d9fb5f8487f32db447f3bc0b4
parent23b9ef799eb0d322c7dcfe796b196cce3cea6435 (diff)
downloadmitmproxy-b14eb57db190ae08266d96dbadc2458595914518.tar.gz
mitmproxy-b14eb57db190ae08266d96dbadc2458595914518.tar.bz2
mitmproxy-b14eb57db190ae08266d96dbadc2458595914518.zip
Add SSL & Connect timings
-rw-r--r--examples/har_dump.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py
index 56508cdc..d7ec9096 100644
--- a/examples/har_dump.py
+++ b/examples/har_dump.py
@@ -17,6 +17,10 @@ from netlib.http import cookies
HAR = {}
+# A list of server seen till now is maintained so we can avoid
+# using 'connect' time for entries that use an existing connection.
+SERVERS_SEEN = set()
+
def start():
"""
@@ -46,21 +50,33 @@ def response(flow):
"""
Called when a server response has been received.
"""
- # TODO: SSL and Connect Timings
- # Calculate raw timings from timestamps.
+ # -1 indicates that these values do not apply to current request
+ ssl_time = -1
+ connect_time = -1
+
+ if flow.server_conn and flow.server_conn not in SERVERS_SEEN:
+ connect_time = (flow.server_conn.timestamp_tcp_setup -
+ flow.server_conn.timestamp_start)
+
+ if flow.server_conn.timestamp_ssl_setup is not None:
+ ssl_time = (flow.server_conn.timestamp_ssl_setup -
+ flow.server_conn.timestamp_tcp_setup)
- # DNS timings can not be calculated for lack of a way to measure it.
- # The same goes for HAR blocked.
+ SERVERS_SEEN.add(flow.server_conn)
+ # Calculate raw timings from timestamps. DNS timings can not be calculated
+ # for lack of a way to measure it. The same goes for HAR blocked.
# mitmproxy will open a server connection as soon as it receives the host
# and port from the client connection. So, the time spent waiting is actually
- # spent waiting between request.timestamp_end and response.timestamp_start thus it
- # correlates to HAR wait instead.
+ # spent waiting between request.timestamp_end and response.timestamp_start
+ # thus it correlates to HAR wait instead.
timings_raw = {
'send': flow.request.timestamp_end - flow.request.timestamp_start,
'receive': flow.response.timestamp_end - flow.response.timestamp_start,
'wait': flow.response.timestamp_start - flow.request.timestamp_end,
+ 'connect': connect_time,
+ 'ssl': ssl_time,
}
# HAR timings are integers in ms, so we re-encode the raw timings to that format.