From bcc496527ebf5faf94025ec7c28992a1ac368140 Mon Sep 17 00:00:00 2001 From: Clemens Date: Mon, 1 Aug 2016 15:21:00 +0200 Subject: [PATCH] replace get_content_view in dumper and flowview --- mitmproxy/builtins/dumper.py | 18 ++++-------------- mitmproxy/console/flowview.py | 32 +++----------------------------- 2 files changed, 7 insertions(+), 43 deletions(-) diff --git a/mitmproxy/builtins/dumper.py b/mitmproxy/builtins/dumper.py index 59f9349d7..b1367e12e 100644 --- a/mitmproxy/builtins/dumper.py +++ b/mitmproxy/builtins/dumper.py @@ -73,20 +73,10 @@ class Dumper(object): elif content: self.echo("") - try: - _, lines = contentviews.get_content_view( - contentviews.get("Auto"), - content, - headers=getattr(message, "headers", None) - ) - except exceptions.ContentViewException: - s = "Content viewer failed: \n" + traceback.format_exc() - ctx.log.debug(s) - _, lines = contentviews.get_content_view( - contentviews.get("Raw"), - content, - headers=getattr(message, "headers", None) - ) + _, lines = contentviews.get_content_view_with_message_encoding( + message, + contentviews.get("Auto") + ) styles = dict( highlight=dict(bold=True), diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py index c354563f0..c1001a5a4 100644 --- a/mitmproxy/console/flowview.py +++ b/mitmproxy/console/flowview.py @@ -207,35 +207,9 @@ class FlowView(tabs.Tabs): def _get_content_view(self, message, viewmode, max_lines, _): - try: - content = message.content - if content != message.raw_content: - enc = "[decoded {}]".format( - message.headers.get("content-encoding") - ) - else: - enc = None - except ValueError: - content = message.raw_content - enc = "[cannot decode]" - try: - query = None - if isinstance(message, models.HTTPRequest): - query = message.query - description, lines = contentviews.get_content_view( - viewmode, content, headers=message.headers, query=query - ) - except exceptions.ContentViewException: - s = "Content viewer failed: \n" + traceback.format_exc() - signals.add_log(s, "error") - description, lines = contentviews.get_content_view( - contentviews.get("Raw"), content, headers=message.headers - ) - description = description.replace("Raw", "Couldn't parse: falling back to Raw") - - if enc: - description = " ".join([enc, description]) - + description, lines = contentviews.get_content_view_with_message_encoding( + message, viewmode + ) # Give hint that you have to tab for the response. if description == "No content" and isinstance(message, models.HTTPRequest): description = "No request content (press tab to view response)"