aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/console.py52
-rw-r--r--test/test_console.py3
2 files changed, 29 insertions, 26 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py
index 2a4588c6..996b845c 100644
--- a/libmproxy/console.py
+++ b/libmproxy/console.py
@@ -54,9 +54,9 @@ def format_keyvals(lst, key="key", val="text", space=5, indent=0):
def format_flow(f, focus, extended=False, padding=2):
if extended:
- ts = ("highlight", utils.format_timestamp(f.request.timestamp) + " ")
+ ts = ("highlight", utils.format_timestamp(f.request.timestamp))
else:
- ts = " "
+ ts = ""
txt = [
ts,
@@ -321,28 +321,31 @@ class ConnectionView(WWrap):
)
def _conn_text(self, conn):
- txt = []
- txt.extend(
- format_keyvals(
- [(h+":", v) for (h, v) in sorted(conn.headers.itemPairs())],
- key = "header",
- val = "text"
+ if conn:
+ txt = []
+ txt.extend(
+ format_keyvals(
+ [(h+":", v) for (h, v) in sorted(conn.headers.itemPairs())],
+ key = "header",
+ val = "text"
+ )
)
- )
- txt.append("\n\n")
- if conn.content:
- if self.state.view_body_mode == VIEW_BODY_BINARY:
- self._view_binary(conn, txt)
- elif self.state.view_body_mode == VIEW_BODY_INDENT:
- self.master.statusbar.update("Calculating pretty mode...")
- self._view_pretty(conn, txt)
- self.master.statusbar.update("")
- else:
- if utils.isBin(conn.content):
+ txt.append("\n\n")
+ if conn.content:
+ if self.state.view_body_mode == VIEW_BODY_BINARY:
self._view_binary(conn, txt)
+ elif self.state.view_body_mode == VIEW_BODY_INDENT:
+ self.master.statusbar.update("Calculating pretty mode...")
+ self._view_pretty(conn, txt)
+ self.master.statusbar.update("")
else:
- self._view_normal(conn, txt)
- return urwid.ListBox([urwid.Text(txt)])
+ if utils.isBin(conn.content):
+ self._view_binary(conn, txt)
+ else:
+ self._view_normal(conn, txt)
+ return urwid.ListBox([urwid.Text(txt)])
+ else:
+ return urwid.ListBox([])
def view_request(self):
self.state.view_flow_mode = VIEW_FLOW_REQUEST
@@ -350,10 +353,9 @@ class ConnectionView(WWrap):
self.w = self.wrap_body(VIEW_FLOW_REQUEST, body)
def view_response(self):
- if self.flow.response:
- self.state.view_flow_mode = VIEW_FLOW_RESPONSE
- body = self._conn_text(self.flow.response)
- self.w = self.wrap_body(VIEW_FLOW_RESPONSE, body)
+ self.state.view_flow_mode = VIEW_FLOW_RESPONSE
+ body = self._conn_text(self.flow.response)
+ self.w = self.wrap_body(VIEW_FLOW_RESPONSE, body)
def refresh_connection(self, c=None):
if c == self.flow:
diff --git a/test/test_console.py b/test/test_console.py
index ffcb31f7..037d86d2 100644
--- a/test/test_console.py
+++ b/test/test_console.py
@@ -81,6 +81,8 @@ class uformat_keyvals(libpry.AutoTree):
("aa", "bb"),
None,
("cc", "dd"),
+ (None, "dd"),
+ (None, "dd"),
]
)
@@ -162,7 +164,6 @@ class uOptions(libpry.AutoTree):
-
tests = [
uformat_keyvals(),
uformat_flow(),