diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-03-20 10:58:43 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-03-20 10:58:43 +1300 |
commit | 215383554525535816accdd8580d06b9e4cf7565 (patch) | |
tree | 157a8938141001336d259cdd1a778e46bec4c743 /libmproxy/console/flowview.py | |
parent | 2739cb4861b5d8b35ab9db0d20128b1bdc5808cb (diff) | |
download | mitmproxy-215383554525535816accdd8580d06b9e4cf7565.tar.gz mitmproxy-215383554525535816accdd8580d06b9e4cf7565.tar.bz2 mitmproxy-215383554525535816accdd8580d06b9e4cf7565.zip |
Refactor pretty view forcing somewhat.
- Use a lookup table of content types -> view modes.
- Add a urlencoded forcing. Remove "html" - at the moment it's the same as
"xmlish".
- Display type when forced.
Diffstat (limited to 'libmproxy/console/flowview.py')
-rw-r--r-- | libmproxy/console/flowview.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index 6038a777..4c4cc86b 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -199,32 +199,34 @@ class ConnectionView(common.WWrap): val = "text" ) - def _find_pretty_view(self, content, hdrItems, pretty_type=common.VIEW_BODY_PRETTY_TYPE_AUTO): ctype = None if pretty_type == common.VIEW_BODY_PRETTY_TYPE_AUTO: + pretty_type == None for i in hdrItems: if i[0].lower() == "content-type": ctype = i[1] break - else: - ctype = common.BODY_PRETTY_TYPES[pretty_type] + ct = utils.parse_content_type(ctype) if ctype else None + if ct: + pretty_type = common.BODY_PRETTY_TYPES.get("%s/%s"%(ct[0], ct[1])) + if not pretty_type and utils.isXML(content): + pretty_type = common.VIEW_BODY_PRETTY_TYPE_XML - if ctype and flow.HDR_FORM_URLENCODED in ctype: + if pretty_type == common.VIEW_BODY_PRETTY_TYPE_URLENCODED: data = utils.urldecode(content) if data: return "URLEncoded form", self._view_flow_urlencoded(data) - if (ctype and ("text/xml" in ctype or "text/html" in ctype)) or utils.isXML(content): + + if pretty_type == common.VIEW_BODY_PRETTY_TYPE_XML: return "Indented XML-ish", self._view_flow_xmlish(content) - elif ctype and "application/json" in ctype: + + if pretty_type == common.VIEW_BODY_PRETTY_TYPE_JSON: lines = utils.pretty_json(content) if lines: return "JSON", self._view_flow_json(lines) - elif ctype and "multipart/form-data" in ctype: - boundary = ctype.split('boundary=') - if len(boundary) > 1: - return "Form data", self._view_flow_formdata(content, boundary[1].split(';')[0]) - return "", self._view_flow_raw(content) + + return "Falling back to raw.", self._view_flow_raw(content) def _cached_conn_text(self, e, content, hdrItems, viewmode, pretty_type): txt = common.format_keyvals( @@ -245,8 +247,10 @@ class ConnectionView(common.WWrap): if e and e != "identity": emsg = "[decoded %s]"%e msg, body = self._find_pretty_view(content, hdrItems, pretty_type) + if pretty_type != common.VIEW_BODY_PRETTY_TYPE_AUTO: - msg += " (forced)" + emsg += " (forced to %s)"%(common.BODY_PRETTY_NAMES[pretty_type]) + if emsg: msg = emsg + " " + msg else: @@ -579,9 +583,9 @@ class ConnectionView(common.WWrap): "Pretty-Print format", ( ("auto detect", "a"), - ("html", "h"), ("json", "j"), - ("xml", "x"), + ("urlencoded", "u"), + ("xmlish", "x"), ), self.master.change_pretty_type ) |