From 586472e364c1fb411711979efa604f2a5128c40d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 11 Feb 2012 11:25:35 +1300 Subject: Revamp the way request and response bodies are displayed. --- libmproxy/console/__init__.py | 5 ---- libmproxy/console/common.py | 20 +++++++------- libmproxy/console/connview.py | 61 ++++++++++++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 36 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 76968ae5..f0c8d833 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -185,11 +185,6 @@ class StatusBar(common.WWrap): urwid.Text( [ self.helptext, - " ", - ('statusbar_text', "["), - ('statusbar_key', "m"), - ('statusbar_text', (":%s]"%common.BODY_VIEWS[self.master.state.view_body_mode])), - ('statusbar_text', boundaddr), ], align="right" ), diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 6fbb5e19..658c94b1 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -38,23 +38,23 @@ def format_keyvals(lst, key="key", val="text", space=5, indent=0): ret = [] if lst: pad = max(len(i[0]) for i in lst if i and i[0]) + space - for i in lst: - if i is None: - ret.extend("\n") - elif i[0] is None: + for i, kv in enumerate(lst): + if kv is None: + ret.extend("") + elif kv[0] is None: ret.append(" "*(pad + indent*2)) - ret.extend(i[1]) - ret.append("\n") + ret.extend(kv[1]) else: ret.extend( [ " "*indent, - (key, i[0]), - " "*(pad-len(i[0])), - (val, i[1]), - "\n" + (key, kv[0]), + " "*(pad-len(kv[0])), + (val, kv[1]), ] ) + if i < len(lst) - 1: + ret.append("\n") return ret diff --git a/libmproxy/console/connview.py b/libmproxy/console/connview.py index 1a5495db..7b9dcb87 100644 --- a/libmproxy/console/connview.py +++ b/libmproxy/console/connview.py @@ -160,14 +160,14 @@ class ConnectionView(common.WWrap): ] def _view_conn_urlencoded(self, lines): - kv = common.format_keyvals( - [(k+":", v) for (k, v) in lines], - key = "header", - val = "text" - ) - return [ - urwid.Text(("highlight", "URLencoded data:\n")), - urwid.Text(kv) + return [ + urwid.Text( + common.format_keyvals( + [(k+":", v) for (k, v) in lines], + key = "header", + val = "text" + ) + ) ] def _find_pretty_view(self, content, hdrItems): @@ -179,18 +179,18 @@ class ConnectionView(common.WWrap): if ctype and flow.HDR_FORM_URLENCODED in ctype: data = utils.urldecode(content) if data: - return self._view_conn_urlencoded(data) + return "URLEncoded form", self._view_conn_urlencoded(data) if utils.isXML(content): - return self._view_conn_xmlish(content) + return "Indented XML-ish", self._view_conn_xmlish(content) elif ctype and "application/json" in ctype: lines = utils.pretty_json(content) if lines: - return self._view_conn_json(lines) + return "JSON", self._view_conn_json(lines) elif ctype and "multipart/form-data" in ctype: boundary = ctype.split('boundary=') if len(boundary) > 1: - return self._view_conn_formdata(content, boundary[1].split(';')[0]) - return self._view_conn_raw(content) + return "FOrm data", self._view_conn_formdata(content, boundary[1].split(';')[0]) + return "", self._view_conn_raw(content) def _cached_conn_text(self, e, content, hdrItems, viewmode): hdr = [] @@ -201,24 +201,43 @@ class ConnectionView(common.WWrap): val = "text" ) ) - hdr.append("\n") - txt = [urwid.Text(hdr)] if content: + msg = "" if viewmode == common.VIEW_BODY_HEX: - txt.extend(self._view_conn_binary(content)) + body = self._view_conn_binary(content) elif viewmode == common.VIEW_BODY_PRETTY: + emsg = "" if e: decoded = encoding.decode(e, content) if decoded: content = decoded if e and e != "identity": - txt.append( - urwid.Text(("highlight", "Decoded %s data:\n"%e)) - ) - txt.extend(self._find_pretty_view(content, hdrItems)) + emsg = "[decoded %s]"%e + msg, body = self._find_pretty_view(content, hdrItems) + if emsg: + msg = emsg + " " + msg else: - txt.extend(self._view_conn_raw(content)) + body = self._view_conn_raw(content) + + title = urwid.AttrWrap(urwid.Columns([ + urwid.Text( + [ + ("statusbar", msg), + ] + ), + urwid.Text( + [ + " ", + ('statusbar_text', "["), + ('statusbar_key', "m"), + ('statusbar_text', (":%s]"%common.BODY_VIEWS[self.master.state.view_body_mode])), + ], + align="right" + ), + ]), "statusbar") + txt.append(title) + txt.extend(body) return urwid.ListBox(txt) def _tab(self, content, active): -- cgit v1.2.3