mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Only cache the calculated body of a view.
This simplifies the code, and loses no time.
This commit is contained in:
parent
2df2fe0e4c
commit
c6ee813479
@ -93,7 +93,7 @@ class FlowViewHeader(common.WWrap):
|
|||||||
|
|
||||||
|
|
||||||
class CallbackCache:
|
class CallbackCache:
|
||||||
@utils.LRUCache(100)
|
@utils.LRUCache(200)
|
||||||
def _callback(self, method, *args, **kwargs):
|
def _callback(self, method, *args, **kwargs):
|
||||||
return getattr(self.obj, method)(*args, **kwargs)
|
return getattr(self.obj, method)(*args, **kwargs)
|
||||||
|
|
||||||
@ -124,14 +124,25 @@ class FlowView(common.WWrap):
|
|||||||
else:
|
else:
|
||||||
self.view_request()
|
self.view_request()
|
||||||
|
|
||||||
def _cached_conn_text(self, content, hdrItems, viewmode):
|
def _cached_content_view(self, viewmode, hdrItems, content):
|
||||||
|
return contentview.get_content_view(viewmode, hdrItems, content)
|
||||||
|
|
||||||
|
def content_view(self, viewmode, conn):
|
||||||
|
return cache.callback(
|
||||||
|
self, "_cached_content_view",
|
||||||
|
viewmode,
|
||||||
|
tuple(tuple(i) for i in conn.headers.lst),
|
||||||
|
conn.content,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _conn_text(self, conn, viewmode):
|
||||||
txt = common.format_keyvals(
|
txt = common.format_keyvals(
|
||||||
[(h+":", v) for (h, v) in hdrItems],
|
[(h+":", v) for (h, v) in conn.headers.lst],
|
||||||
key = "header",
|
key = "header",
|
||||||
val = "text"
|
val = "text"
|
||||||
)
|
)
|
||||||
if content:
|
if conn.content:
|
||||||
msg, body = contentview.get_content_view(viewmode, hdrItems, content)
|
msg, body = self.content_view(viewmode, conn)
|
||||||
title = urwid.AttrWrap(urwid.Columns([
|
title = urwid.AttrWrap(urwid.Columns([
|
||||||
urwid.Text(
|
urwid.Text(
|
||||||
[
|
[
|
||||||
@ -186,14 +197,6 @@ class FlowView(common.WWrap):
|
|||||||
)
|
)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def _conn_text(self, conn, viewmode):
|
|
||||||
return cache.callback(
|
|
||||||
self, "_cached_conn_text",
|
|
||||||
conn.content,
|
|
||||||
tuple(tuple(i) for i in conn.headers.lst),
|
|
||||||
viewmode
|
|
||||||
)
|
|
||||||
|
|
||||||
def view_request(self):
|
def view_request(self):
|
||||||
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
|
self.state.view_flow_mode = common.VIEW_FLOW_REQUEST
|
||||||
body = self._conn_text(
|
body = self._conn_text(
|
||||||
|
Loading…
Reference in New Issue
Block a user