aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorSlobodan Mišković <slobodan@miskovic.ca>2016-10-21 22:05:42 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-10-22 18:28:32 -0700
commit0526d94f4a073cc4d15a02bdbbf447776d75f81d (patch)
treeb4b3b614f041d4fd1b46d81f1cb5ba57e3f40dc8 /examples
parentceb12e86280f754f9147b208818cce9831bf7f86 (diff)
downloadmitmproxy-0526d94f4a073cc4d15a02bdbbf447776d75f81d.tar.gz
mitmproxy-0526d94f4a073cc4d15a02bdbbf447776d75f81d.tar.bz2
mitmproxy-0526d94f4a073cc4d15a02bdbbf447776d75f81d.zip
Handle `bytes` in request parameters
Diffstat (limited to 'examples')
-rw-r--r--examples/har_dump.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/examples/har_dump.py b/examples/har_dump.py
index 560b9adc..3ba08968 100644
--- a/examples/har_dump.py
+++ b/examples/har_dump.py
@@ -139,7 +139,7 @@ def response(flow):
if flow.request.method in ["POST", "PUT", "PATCH"]:
entry["request"]["postData"] = {
"mimeType": flow.request.headers.get("Content-Type", "").split(";")[0],
- "text": flow.request.content,
+ "text": _always_string(flow.request.content),
"params": name_value(flow.request.urlencoded_form)
}
@@ -213,4 +213,12 @@ def name_value(obj):
"""
Convert (key, value) pairs to HAR format.
"""
- return [{"name": k, "value": v} for k, v in obj.items()]
+ return [{"name": _always_string(k), "value": _always_string(v)} for k, v in obj.items()]
+
+def _always_string(byte_or_str):
+ """
+ Makes sure we get text back instead of `bytes` since json.dumps dies on `bytes`
+ """
+ if isinstance(byte_or_str, bytes):
+ return byte_or_str.decode('utf8')
+ return byte_or_str