mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 15:55:28 +00:00
Simplify content generation in flow view
This commit is contained in:
parent
8f0e4a9bdd
commit
cfeee347d9
@ -161,26 +161,16 @@ class FlowView(urwid.WidgetWrap):
|
||||
)
|
||||
return self.state.default_body_view if override is None else override
|
||||
|
||||
def conn_text_raw(self, conn):
|
||||
"""
|
||||
Based on a request/response, conn, returns the elements for
|
||||
display.
|
||||
"""
|
||||
headers = common.format_keyvals(
|
||||
def conn_text(self, conn):
|
||||
if conn:
|
||||
txt = common.format_keyvals(
|
||||
[(h+":", v) for (h, v) in conn.headers.lst],
|
||||
key = "header",
|
||||
val = "text"
|
||||
)
|
||||
viewmode = self.viewmode_get()
|
||||
msg, body = self.content_view(viewmode, conn)
|
||||
return headers, msg, body
|
||||
|
||||
def conn_text_merge(self, headers, msg, body):
|
||||
"""
|
||||
Grabs what is returned by conn_text_raw and merges them all
|
||||
toghether, mainly used by conn_text
|
||||
"""
|
||||
viewmode = self.viewmode_get()
|
||||
cols = [urwid.Text(
|
||||
[
|
||||
("heading", msg),
|
||||
@ -196,21 +186,22 @@ class FlowView(urwid.WidgetWrap):
|
||||
align="right"
|
||||
)
|
||||
)
|
||||
|
||||
title = urwid.AttrWrap(urwid.Columns(cols), "heading")
|
||||
headers.append(title)
|
||||
headers.extend(body)
|
||||
|
||||
return headers
|
||||
|
||||
def conn_text(self, conn):
|
||||
"""
|
||||
Same as conn_text_raw, but returns result wrapped in a listbox ready for
|
||||
usage.
|
||||
"""
|
||||
headers, msg, body = self.conn_text_raw(conn)
|
||||
merged = self.conn_text_merge(headers, msg, body)
|
||||
return searchable.Searchable(self.state, merged)
|
||||
txt.append(title)
|
||||
txt.extend(body)
|
||||
else:
|
||||
txt = [
|
||||
urwid.Text(""),
|
||||
urwid.Text(
|
||||
[
|
||||
("highlight", "No response. Press "),
|
||||
("key", "e"),
|
||||
("highlight", " and edit any aspect to add one."),
|
||||
]
|
||||
)
|
||||
]
|
||||
return searchable.Searchable(self.state, txt)
|
||||
|
||||
def _tab(self, content, attr):
|
||||
p = urwid.Text(content)
|
||||
@ -253,22 +244,7 @@ class FlowView(urwid.WidgetWrap):
|
||||
|
||||
def view_response(self):
|
||||
self.state.view_flow_mode = common.VIEW_FLOW_RESPONSE
|
||||
if self.flow.response:
|
||||
body = self.conn_text(self.flow.response)
|
||||
else:
|
||||
body = searchable.Searchable(
|
||||
self.state,
|
||||
[
|
||||
urwid.Text(""),
|
||||
urwid.Text(
|
||||
[
|
||||
("highlight", "No response. Press "),
|
||||
("key", "e"),
|
||||
("highlight", " and edit any aspect to add one."),
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
self._w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
|
||||
|
||||
def set_method_raw(self, m):
|
||||
|
Loading…
Reference in New Issue
Block a user