diff options
Diffstat (limited to 'mitmproxy/contentviews.py')
-rw-r--r-- | mitmproxy/contentviews.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mitmproxy/contentviews.py b/mitmproxy/contentviews.py index 28c57f06..006967d7 100644 --- a/mitmproxy/contentviews.py +++ b/mitmproxy/contentviews.py @@ -62,11 +62,18 @@ KEY_MAX = 30 def pretty_json(s): + # type: (bytes) -> bytes try: p = json.loads(s) except ValueError: return None - return json.dumps(p, sort_keys=True, indent=4) + pretty = json.dumps(p, sort_keys=True, indent=4, ensure_ascii=False) + if isinstance(pretty, six.text_type): + # json.dumps _may_ decide to return unicode, if the JSON object is not ascii. + # From limited testing this is always valid utf8 (otherwise json.loads will fail earlier), + # so we can just re-encode it here. + return pretty.encode("utf8", "strict") + return pretty def format_dict(d): @@ -153,7 +160,7 @@ class ViewRaw(View): content_types = [] def __call__(self, data, **metadata): - return "Raw", format_text(data) + return "Raw", format_text(strutils.bytes_to_escaped_str(data)) class ViewHex(View): |