diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-12-09 19:02:55 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-12-09 19:02:55 +0100 |
commit | f53f079f917603a37fa92718e22af1c1c25988fa (patch) | |
tree | 36c78e49c63c65a44b180c71861a341d990a39aa /mitmproxy/contentviews/auto.py | |
parent | d1c72574d5f0e83de9bdfa7c921134052b74ae44 (diff) | |
download | mitmproxy-f53f079f917603a37fa92718e22af1c1c25988fa.tar.gz mitmproxy-f53f079f917603a37fa92718e22af1c1c25988fa.tar.bz2 mitmproxy-f53f079f917603a37fa92718e22af1c1c25988fa.zip |
split contentviews.py into mitmproxy.contentviews
Diffstat (limited to 'mitmproxy/contentviews/auto.py')
-rw-r--r-- | mitmproxy/contentviews/auto.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/mitmproxy/contentviews/auto.py b/mitmproxy/contentviews/auto.py new file mode 100644 index 00000000..2b08f165 --- /dev/null +++ b/mitmproxy/contentviews/auto.py @@ -0,0 +1,27 @@ +from mitmproxy.net import http +from mitmproxy.utils import strutils +from . import base +from mitmproxy.contentviews import get, content_types_map + +class ViewAuto(base.View): + name = "Auto" + prompt = ("auto", "a") + content_types = [] + + def __call__(self, data, **metadata): + headers = metadata.get("headers", {}) + ctype = headers.get("content-type") + if data and ctype: + ct = http.parse_content_type(ctype) if ctype else None + ct = "%s/%s" % (ct[0], ct[1]) + if ct in content_types_map: + return content_types_map[ct][0](data, **metadata) + elif strutils.is_xml(data): + return get("XML")(data, **metadata) + if metadata.get("query"): + return get("Query")(data, **metadata) + if data and strutils.is_mostly_bin(data): + return get("Hex")(data) + if not data: + return "No content", [] + return get("Raw")(data) |