diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-04 14:38:14 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-15 12:00:23 +0530 |
commit | 55f1ffe0b100c9aa2a24b041a91091601ea4575d (patch) | |
tree | 80a23ffabc36e60054a4a5fb13689d5b76be25eb /examples/har_dump.py | |
parent | a479c51465deae7be98ddba07ca2138fe6014d77 (diff) | |
download | mitmproxy-55f1ffe0b100c9aa2a24b041a91091601ea4575d.tar.gz mitmproxy-55f1ffe0b100c9aa2a24b041a91091601ea4575d.tar.bz2 mitmproxy-55f1ffe0b100c9aa2a24b041a91091601ea4575d.zip |
Format Cookies according to the HAR Spec
Diffstat (limited to 'examples/har_dump.py')
-rw-r--r-- | examples/har_dump.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py index d19cad36..39093402 100644 --- a/examples/har_dump.py +++ b/examples/har_dump.py @@ -13,6 +13,8 @@ import pytz import mitmproxy from mitmproxy import version +from netlib.http import cookies + HAR = {} @@ -44,8 +46,6 @@ def response(flow): """ Called when a server response has been received. """ - entries = HAR["log"]["entries"] - # TODO: SSL and Connect Timings # Calculate raw timings from timestamps. @@ -78,14 +78,14 @@ def response(flow): response_body_decoded_size = len(flow.response.content) response_body_compression = response_body_decoded_size - response_body_size - entries.append({ + HAR["log"]["entries"].append({ "startedDateTime": started_date_time, "time": full_time, "request": { "method": flow.request.method, "url": flow.request.url, "httpVersion": flow.request.http_version, - "cookies": name_value(flow.request.cookies), + "cookies": format_request_cookies(flow.request.cookies.fields), "headers": name_value(flow.request.headers), "queryString": name_value(flow.request.query or {}), "headersSize": len(str(flow.request.headers)), @@ -95,7 +95,7 @@ def response(flow): "status": flow.response.status_code, "statusText": flow.response.reason, "httpVersion": flow.response.http_version, - "cookies": name_value(flow.response.cookies), + "cookies": format_response_cookies(flow.response.cookies.fields), "headers": name_value(flow.response.headers), "content": { "size": response_body_size, @@ -127,6 +127,30 @@ def done(): # TODO: Log results via mitmproxy.ctx.log +def format_cookies(cookies): + cookie_list = [] + + for name, value, attrs in cookies: + cookie_har = { + "name": name, + "value": value, + } + cookie_har.update(attrs) + # print(attrs) + + cookie_list.append(cookie_har) + + return cookie_list + + +def format_request_cookies(fields): + return format_cookies(cookies.group_cookies(fields)) + + +def format_response_cookies(fields): + return format_cookies((c[0], c[1].value, c[1].attrs) for c in fields) + + def name_value(obj): """ Convert (key, value) pairs to HAR format. |