diff options
Diffstat (limited to 'libmproxy/console/flowview.py')
-rw-r--r-- | libmproxy/console/flowview.py | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 19917555..3e13fab4 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -1,15 +1,17 @@ from __future__ import absolute_import import os +import traceback import sys + import urwid from netlib import odict from netlib.http.semantics import CONTENT_MISSING, Headers - -from . import common, grideditor, contentview, signals, searchable, tabs +from . import common, grideditor, signals, searchable, tabs from . import flowdetailview -from .. import utils, controller +from .. import utils, controller, contentviews from ..models import HTTPRequest, HTTPResponse, decoded +from ..exceptions import ContentViewException class SearchError(Exception): @@ -165,10 +167,10 @@ class FlowView(tabs.Tabs): if flow == self.flow: self.show() - def content_view(self, viewmode, conn): - if conn.content == CONTENT_MISSING: + def content_view(self, viewmode, message): + if message.body == CONTENT_MISSING: msg, body = "", [urwid.Text([("error", "[content missing]")])] - return (msg, body) + return msg, body else: full = self.state.get_flow_setting( self.flow, @@ -178,16 +180,44 @@ class FlowView(tabs.Tabs): if full: limit = sys.maxsize else: - limit = contentview.VIEW_CUTOFF - description, text_objects = cache.get( - contentview.get_content_view, + limit = contentviews.VIEW_CUTOFF + return cache.get( + self._get_content_view, viewmode, - conn.headers, - conn.content, - limit, - isinstance(conn, HTTPRequest) + message, + limit + ) + + def _get_content_view(self, viewmode, message, max_lines): + + try: + description, lines = contentviews.get_content_view( + viewmode, message.body, headers=message.headers + ) + except ContentViewException: + s = "Content viewer failed: \n" + traceback.format_exc() + signals.add_event(s, "error") + description, lines = contentviews.get_content_view( + contentviews.get("Raw"), message.body, headers=message.headers ) - return (description, text_objects) + description = description.replace("Raw", "Couldn't parse: falling back to Raw") + + # Give hint that you have to tab for the response. + if description == "No content" and isinstance(message, HTTPRequest): + description = "No request content (press tab to view response)" + + text_objects = [] + for line in lines: + text_objects.append(urwid.Text(line)) + if len(text_objects) == max_lines: + text_objects.append(urwid.Text([ + ("highlight", "Stopped displaying data after %d lines. Press " % max_lines), + ("key", "f"), + ("highlight", " to load all data.") + ])) + break + + return description, text_objects def viewmode_get(self): override = self.state.get_flow_setting( @@ -211,9 +241,7 @@ class FlowView(tabs.Tabs): [ ("heading", msg), ] - ) - ] - cols.append( + ), urwid.Text( [ " ", @@ -223,7 +251,7 @@ class FlowView(tabs.Tabs): ], align="right" ) - ) + ] title = urwid.AttrWrap(urwid.Columns(cols), "heading") txt.append(title) @@ -455,7 +483,7 @@ class FlowView(tabs.Tabs): self.state.add_flow_setting( self.flow, (self.tab_offset, "prettyview"), - contentview.get_by_shortcut(t) + contentviews.get_by_shortcut(t) ) signals.flow_change.send(self, flow = self.flow) @@ -595,7 +623,7 @@ class FlowView(tabs.Tabs): scope = "s" common.ask_copy_part(scope, self.flow, self.master, self.state) elif key == "m": - p = list(contentview.view_prompts) + p = list(contentviews.view_prompts) p.insert(0, ("Clear", "C")) signals.status_prompt_onekey.send( self, |