aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-08-08 13:56:12 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-08-15 12:00:23 +0530
commita2a8283fa419ab8eb3406952802044cfabdd4f88 (patch)
treef5e167b1cda48c0e4bcd4cb95fba77d7eb4ae4eb
parent3caebe7e7369bebb44421177d9b2f4efbf0bc79b (diff)
downloadmitmproxy-a2a8283fa419ab8eb3406952802044cfabdd4f88.tar.gz
mitmproxy-a2a8283fa419ab8eb3406952802044cfabdd4f88.tar.bz2
mitmproxy-a2a8283fa419ab8eb3406952802044cfabdd4f88.zip
Improve cookies formatting
-rw-r--r--examples/har_dump.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py
index 39093402..298f76a0 100644
--- a/examples/har_dump.py
+++ b/examples/har_dump.py
@@ -70,8 +70,7 @@ def response(flow):
# Timings set to -1 will be ignored as per spec.
full_time = sum(v for v in timings.values() if v > -1)
- started_date_time = datetime.utcfromtimestamp(
- flow.request.timestamp_start).replace(tzinfo=pytz.timezone("UTC")).isoformat()
+ started_date_time = format_datetime(datetime.utcfromtimestamp(flow.request.timestamp_start))
# Size calculations
response_body_size = len(flow.response.content)
@@ -127,6 +126,10 @@ def done():
# TODO: Log results via mitmproxy.ctx.log
+def format_datetime(dt):
+ return dt.replace(tzinfo=pytz.timezone("UTC")).isoformat()
+
+
def format_cookies(cookies):
cookie_list = []
@@ -135,8 +138,20 @@ def format_cookies(cookies):
"name": name,
"value": value,
}
- cookie_har.update(attrs)
- # print(attrs)
+
+ # HAR only needs some attributes
+ for key in ["path", "domain", "comment"]:
+ if key in attrs:
+ cookie_har[key] = attrs[key]
+
+ # These keys need to be boolean!
+ for key in ["httpOnly", "secure"]:
+ cookie_har[key] = bool(key in attrs)
+
+ # Expiration time needs to be formatted
+ expire_ts = cookies.get_expiration_ts(attrs)
+ if expire_ts:
+ cookie_har["expires"] = format_datetime(datetime.fromtimestamp(expire_ts))
cookie_list.append(cookie_har)