diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-08-18 17:42:40 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-08-18 17:42:40 +1200 |
commit | b70e91bbd4548d95429db6a7830c988d334e9990 (patch) | |
tree | 019b5c4c9ace8a3f79880987a4cd634c20e2c2bc | |
parent | e8553f966f63923d42e0ef380d82794d73f2637d (diff) | |
download | mitmproxy-b70e91bbd4548d95429db6a7830c988d334e9990.tar.gz mitmproxy-b70e91bbd4548d95429db6a7830c988d334e9990.tar.bz2 mitmproxy-b70e91bbd4548d95429db6a7830c988d334e9990.zip |
Send tracebacks from content viewers to event log.
Also, 100% test coverage for content viewers.
-rw-r--r-- | libmproxy/console/contentview.py | 5 | ||||
-rw-r--r-- | libmproxy/console/flowview.py | 2 | ||||
-rw-r--r-- | test/test_console_contentview.py | 25 |
3 files changed, 24 insertions, 8 deletions
diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 763baab1..359b3d3c 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -336,7 +336,7 @@ def get(name): return i -def get_content_view(viewmode, hdrItems, content, limit): +def get_content_view(viewmode, hdrItems, content, limit, logfunc): """ Returns a (msg, body) tuple. """ @@ -355,7 +355,8 @@ def get_content_view(viewmode, hdrItems, content, limit): # Third-party viewers can fail in unexpected ways... except Exception, e: s = traceback.format_exc() - return "", _view_text(s, len(s), len(s)) + s = "Content viewer failed: \n" + s + logfunc(s) ret = None if not ret: ret = get("Raw")(hdrs, content, limit) diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index f57ab3e4..a6ee41eb 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -128,7 +128,7 @@ class FlowView(common.WWrap): self.view_request() def _cached_content_view(self, viewmode, hdrItems, content, limit): - return contentview.get_content_view(viewmode, hdrItems, content, limit) + return contentview.get_content_view(viewmode, hdrItems, content, limit, self.master.add_event) def content_view(self, viewmode, conn): full = self.state.get_flow_setting( diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index d2ab72dc..4ebef95b 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -160,7 +160,8 @@ Larry cv.get("Raw"), [["content-type", "application/json"]], "[1, 2, 3]", - 1000 + 1000, + lambda x: None ) assert "Raw" in r[0] @@ -168,7 +169,8 @@ Larry cv.get("Auto"), [["content-type", "application/json"]], "[1, 2, 3]", - 1000 + 1000, + lambda x: None ) assert r[0] == "JSON" @@ -176,18 +178,30 @@ Larry cv.get("Auto"), [["content-type", "application/json"]], "[1, 2", - 1000 + 1000, + lambda x: None ) assert "Raw" in r[0] r = cv.get_content_view( + cv.get("AMF"), + [], + "[1, 2", + 1000, + lambda x: None + ) + assert "Raw" in r[0] + + + r = cv.get_content_view( cv.get("Auto"), [ ["content-type", "application/json"], ["content-encoding", "gzip"] ], encoding.encode('gzip', "[1, 2, 3]"), - 1000 + 1000, + lambda x: None ) assert "decoded gzip" in r[0] assert "JSON" in r[0] @@ -199,7 +213,8 @@ Larry ["content-encoding", "gzip"] ], encoding.encode('gzip', "[1, 2, 3]"), - 1000 + 1000, + lambda x: None ) assert "decoded gzip" in r[0] assert "Raw" in r[0] |