From bb1400777bf0ecbb9b3b937c4767cdd8c79c9264 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 21 Jul 2016 18:30:09 -0700 Subject: [PATCH 1/5] fix #1390 --- mitmproxy/console/master.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 4fd6cb787..21ad97e80 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -86,10 +86,10 @@ class ConsoleState(flow.State): def set_focus(self, idx): if self.view: - if idx >= len(self.view): - idx = len(self.view) - 1 - elif idx < 0: + if idx is None or idx < 0: idx = 0 + elif idx >= len(self.view): + idx = len(self.view) - 1 self.focus = idx else: self.focus = None From f5841c705c6ddf4d04384cf925c80af0831653d1 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 21 Jul 2016 18:30:48 -0700 Subject: [PATCH 2/5] fix #1392 --- mitmproxy/console/flowview.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py index 938c8e86f..d85856cc6 100644 --- a/mitmproxy/console/flowview.py +++ b/mitmproxy/console/flowview.py @@ -605,11 +605,11 @@ class FlowView(tabs.Tabs): if key == "b": if self.tab_offset == TAB_REQ: common.ask_save_body( - "q", self.master, self.state, self.flow + "q", self.flow ) else: common.ask_save_body( - "s", self.master, self.state, self.flow + "s", self.flow ) elif key == "e": if self.tab_offset == TAB_REQ: From 0911f4908b8481e7793b0d3632add7112f69e9a9 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 21 Jul 2016 18:31:12 -0700 Subject: [PATCH 3/5] fix #1391 --- mitmproxy/console/common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mitmproxy/console/common.py b/mitmproxy/console/common.py index 281fd6584..6f0b46ddc 100644 --- a/mitmproxy/console/common.py +++ b/mitmproxy/console/common.py @@ -216,7 +216,7 @@ def copy_to_clipboard_or_prompt(data): def format_flow_data(key, scope, flow): - data = "" + data = b"" if scope in ("q", "b"): request = flow.request.copy() request.decode(strict=False) @@ -230,7 +230,7 @@ def format_flow_data(key, scope, flow): raise ValueError("Unknown key: {}".format(key)) if scope == "b" and flow.request.raw_content and flow.response: # Add padding between request and response - data += "\r\n" * 2 + data += b"\r\n" * 2 if scope in ("s", "b") and flow.response: response = flow.response.copy() response.decode(strict=False) @@ -293,7 +293,7 @@ def ask_save_body(scope, flow): ) elif scope == "b" and request_has_content and response_has_content: ask_save_path( - (flow.request.get_content(strict=False) + "\n" + + (flow.request.get_content(strict=False) + b"\n" + flow.response.get_content(strict=False)), "Save request & response content to" ) From 2ce7166a45a01fb99091263d991505c8ffa39021 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 21 Jul 2016 18:32:25 -0700 Subject: [PATCH 4/5] improve console ux for duplication/creation --- mitmproxy/console/flowlist.py | 6 ++++-- mitmproxy/console/flowview.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mitmproxy/console/flowlist.py b/mitmproxy/console/flowlist.py index 53e934f16..6beac203c 100644 --- a/mitmproxy/console/flowlist.py +++ b/mitmproxy/console/flowlist.py @@ -193,7 +193,8 @@ class ConnectionItem(urwid.WidgetWrap): signals.flowlist_change.send(self) elif key == "D": f = self.master.duplicate_flow(self.flow) - self.master.view_flow(f) + self.master.state.set_focus_flow(f) + signals.flowlist_change.send(self) elif key == "m": if self.state.flow_marked(self.flow): self.state.set_flow_marked(self.flow, False) @@ -356,7 +357,8 @@ class FlowListBox(urwid.ListBox): return scheme, host, port, path = parts f = self.master.create_request(method, scheme, host, port, path) - self.master.view_flow(f) + self.master.state.set_focus_flow(f) + signals.flowlist_change.send(self) def keypress(self, size, key): key = common.shortcuts(key) diff --git a/mitmproxy/console/flowview.py b/mitmproxy/console/flowview.py index d85856cc6..ac9570fff 100644 --- a/mitmproxy/console/flowview.py +++ b/mitmproxy/console/flowview.py @@ -567,6 +567,7 @@ class FlowView(tabs.Tabs): self.state.delete_flow(f) elif key == "D": f = self.master.duplicate_flow(self.flow) + signals.pop_view_state.send(self) self.master.view_flow(f) signals.status_message.send(message="Duplicated.") elif key == "p": From b28954ea5fb49be6433ea7a187bee1f7baef3304 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 21 Jul 2016 18:32:47 -0700 Subject: [PATCH 5/5] minor fixes --- mitmproxy/console/master.py | 13 +------------ mitmproxy/controller.py | 2 -- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 21ad97e80..f4617f621 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -254,10 +254,6 @@ class ConsoleMaster(flow.FlowMaster): expire=1 ) - def load_script(self, command, use_reloader=True): - # We default to using the reloader in the console ui. - return super(ConsoleMaster, self).load_script(command, use_reloader) - def sig_add_log(self, sender, e, level): if self.options.verbosity < utils.log_tier(level): return @@ -352,7 +348,7 @@ class ConsoleMaster(flow.FlowMaster): try: return flow.read_flows_from_paths(path) except exceptions.FlowReadException as e: - signals.status_message.send(message=e.strerror) + signals.status_message.send(message=str(e)) def client_playback_path(self, path): if not isinstance(path, list): @@ -748,10 +744,3 @@ class ConsoleMaster(flow.FlowMaster): direction=direction, ), "info") self.add_log(strutils.bytes_to_escaped_str(message.content), "debug") - - @controller.handler - def script_change(self, script): - if super(ConsoleMaster, self).script_change(script): - signals.status_message.send(message='"{}" reloaded.'.format(script.path)) - else: - signals.status_message.send(message='Error reloading "{}".'.format(script.path)) diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 070ec8620..35817a85d 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -37,8 +37,6 @@ Events = frozenset([ "configure", "done", "tick", - - "script_change", ])