mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-07 10:40:09 +00:00
Send tracebacks from content viewers to event log.
Also, 100% test coverage for content viewers.
This commit is contained in:
parent
e8553f966f
commit
b70e91bbd4
@ -336,7 +336,7 @@ def get(name):
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
def get_content_view(viewmode, hdrItems, content, limit):
|
def get_content_view(viewmode, hdrItems, content, limit, logfunc):
|
||||||
"""
|
"""
|
||||||
Returns a (msg, body) tuple.
|
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...
|
# Third-party viewers can fail in unexpected ways...
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
s = traceback.format_exc()
|
s = traceback.format_exc()
|
||||||
return "", _view_text(s, len(s), len(s))
|
s = "Content viewer failed: \n" + s
|
||||||
|
logfunc(s)
|
||||||
ret = None
|
ret = None
|
||||||
if not ret:
|
if not ret:
|
||||||
ret = get("Raw")(hdrs, content, limit)
|
ret = get("Raw")(hdrs, content, limit)
|
||||||
|
@ -128,7 +128,7 @@ class FlowView(common.WWrap):
|
|||||||
self.view_request()
|
self.view_request()
|
||||||
|
|
||||||
def _cached_content_view(self, viewmode, hdrItems, content, limit):
|
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):
|
def content_view(self, viewmode, conn):
|
||||||
full = self.state.get_flow_setting(
|
full = self.state.get_flow_setting(
|
||||||
|
@ -160,7 +160,8 @@ Larry
|
|||||||
cv.get("Raw"),
|
cv.get("Raw"),
|
||||||
[["content-type", "application/json"]],
|
[["content-type", "application/json"]],
|
||||||
"[1, 2, 3]",
|
"[1, 2, 3]",
|
||||||
1000
|
1000,
|
||||||
|
lambda x: None
|
||||||
)
|
)
|
||||||
assert "Raw" in r[0]
|
assert "Raw" in r[0]
|
||||||
|
|
||||||
@ -168,7 +169,8 @@ Larry
|
|||||||
cv.get("Auto"),
|
cv.get("Auto"),
|
||||||
[["content-type", "application/json"]],
|
[["content-type", "application/json"]],
|
||||||
"[1, 2, 3]",
|
"[1, 2, 3]",
|
||||||
1000
|
1000,
|
||||||
|
lambda x: None
|
||||||
)
|
)
|
||||||
assert r[0] == "JSON"
|
assert r[0] == "JSON"
|
||||||
|
|
||||||
@ -176,10 +178,21 @@ Larry
|
|||||||
cv.get("Auto"),
|
cv.get("Auto"),
|
||||||
[["content-type", "application/json"]],
|
[["content-type", "application/json"]],
|
||||||
"[1, 2",
|
"[1, 2",
|
||||||
1000
|
1000,
|
||||||
|
lambda x: None
|
||||||
)
|
)
|
||||||
assert "Raw" in r[0]
|
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(
|
r = cv.get_content_view(
|
||||||
cv.get("Auto"),
|
cv.get("Auto"),
|
||||||
[
|
[
|
||||||
@ -187,7 +200,8 @@ Larry
|
|||||||
["content-encoding", "gzip"]
|
["content-encoding", "gzip"]
|
||||||
],
|
],
|
||||||
encoding.encode('gzip', "[1, 2, 3]"),
|
encoding.encode('gzip', "[1, 2, 3]"),
|
||||||
1000
|
1000,
|
||||||
|
lambda x: None
|
||||||
)
|
)
|
||||||
assert "decoded gzip" in r[0]
|
assert "decoded gzip" in r[0]
|
||||||
assert "JSON" in r[0]
|
assert "JSON" in r[0]
|
||||||
@ -199,7 +213,8 @@ Larry
|
|||||||
["content-encoding", "gzip"]
|
["content-encoding", "gzip"]
|
||||||
],
|
],
|
||||||
encoding.encode('gzip', "[1, 2, 3]"),
|
encoding.encode('gzip', "[1, 2, 3]"),
|
||||||
1000
|
1000,
|
||||||
|
lambda x: None
|
||||||
)
|
)
|
||||||
assert "decoded gzip" in r[0]
|
assert "decoded gzip" in r[0]
|
||||||
assert "Raw" in r[0]
|
assert "Raw" in r[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user