mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
Improve cookies formatting
This commit is contained in:
parent
3caebe7e73
commit
a2a8283fa4
@ -70,8 +70,7 @@ def response(flow):
|
|||||||
# Timings set to -1 will be ignored as per spec.
|
# Timings set to -1 will be ignored as per spec.
|
||||||
full_time = sum(v for v in timings.values() if v > -1)
|
full_time = sum(v for v in timings.values() if v > -1)
|
||||||
|
|
||||||
started_date_time = datetime.utcfromtimestamp(
|
started_date_time = format_datetime(datetime.utcfromtimestamp(flow.request.timestamp_start))
|
||||||
flow.request.timestamp_start).replace(tzinfo=pytz.timezone("UTC")).isoformat()
|
|
||||||
|
|
||||||
# Size calculations
|
# Size calculations
|
||||||
response_body_size = len(flow.response.content)
|
response_body_size = len(flow.response.content)
|
||||||
@ -127,6 +126,10 @@ def done():
|
|||||||
# TODO: Log results via mitmproxy.ctx.log
|
# TODO: Log results via mitmproxy.ctx.log
|
||||||
|
|
||||||
|
|
||||||
|
def format_datetime(dt):
|
||||||
|
return dt.replace(tzinfo=pytz.timezone("UTC")).isoformat()
|
||||||
|
|
||||||
|
|
||||||
def format_cookies(cookies):
|
def format_cookies(cookies):
|
||||||
cookie_list = []
|
cookie_list = []
|
||||||
|
|
||||||
@ -135,8 +138,20 @@ def format_cookies(cookies):
|
|||||||
"name": name,
|
"name": name,
|
||||||
"value": value,
|
"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)
|
cookie_list.append(cookie_har)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user