diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-12-16 00:13:18 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-12-16 05:43:38 +0100 |
commit | 388fa7e716aa634f841059f50a731c38c71dd36f (patch) | |
tree | cfac4930c89934a8a9b50d421e2d57c78b09eaee | |
parent | 6b5673e84911f3e2b1599c22c9b4f482a55b9ef1 (diff) | |
download | mitmproxy-388fa7e716aa634f841059f50a731c38c71dd36f.tar.gz mitmproxy-388fa7e716aa634f841059f50a731c38c71dd36f.tar.bz2 mitmproxy-388fa7e716aa634f841059f50a731c38c71dd36f.zip |
remove intercept events, update view manually
-rw-r--r-- | mitmproxy/addons/intercept.py | 3 | ||||
-rw-r--r-- | mitmproxy/flow.py | 9 | ||||
-rw-r--r-- | mitmproxy/tools/console/flowlist.py | 15 | ||||
-rw-r--r-- | mitmproxy/tools/console/flowview.py | 10 | ||||
-rw-r--r-- | mitmproxy/tools/web/app.py | 14 | ||||
-rw-r--r-- | mitmproxy/tools/web/master.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/test_flow.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/test_web_app.py | 4 |
8 files changed, 33 insertions, 34 deletions
diff --git a/mitmproxy/addons/intercept.py b/mitmproxy/addons/intercept.py index 0efc4337..4a3fe17e 100644 --- a/mitmproxy/addons/intercept.py +++ b/mitmproxy/addons/intercept.py @@ -1,4 +1,3 @@ -from mitmproxy import ctx from mitmproxy import flowfilter from mitmproxy import exceptions @@ -25,7 +24,7 @@ class Intercept: not f.request.is_replay, ]) if should_intercept: - f.intercept(ctx.master) + f.intercept() # Handlers diff --git a/mitmproxy/flow.py b/mitmproxy/flow.py index 605802c6..7034cb4a 100644 --- a/mitmproxy/flow.py +++ b/mitmproxy/flow.py @@ -157,7 +157,7 @@ class Flow(stateobject.StateObject): def killable(self): return self.reply and self.reply.state in {"handled", "taken"} - def kill(self, master): + def kill(self): """ Kill this request. """ @@ -170,9 +170,8 @@ class Flow(stateobject.StateObject): self.reply.kill(force=True) self.reply.commit() self.live = False - master.addons("kill", self) - def intercept(self, master): + def intercept(self): """ Intercept this Flow. Processing will stop until resume is called. @@ -181,9 +180,8 @@ class Flow(stateobject.StateObject): return self.intercepted = True self.reply.take() - master.addons("intercept", self) - def resume(self, master): + def resume(self): """ Continue with the flow - called after an intercept(). """ @@ -192,4 +190,3 @@ class Flow(stateobject.StateObject): self.intercepted = False self.reply.ack() self.reply.commit() - master.addons("resume", self) diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py index fd6b3bab..02265143 100644 --- a/mitmproxy/tools/console/flowlist.py +++ b/mitmproxy/tools/console/flowlist.py @@ -165,12 +165,12 @@ class FlowItem(urwid.WidgetWrap): (maxcol,) = xxx_todo_changeme key = common.shortcuts(key) if key == "a": - self.flow.resume(self.master) - signals.flowlist_change.send(self) + self.flow.resume() + self.master.view.update(self.flow) elif key == "d": if self.flow.killable: - self.flow.kill(self.master) - self.master.view.remove(self.master.view.focus.flow) + self.flow.kill() + self.master.view.remove(self.flow) elif key == "D": cp = self.flow.copy() self.master.view.add(cp) @@ -232,7 +232,8 @@ class FlowItem(urwid.WidgetWrap): ) elif key == "X": if self.flow.killable: - self.flow.kill(self.master) + self.flow.kill() + self.master.view.update(self.flow) elif key == "enter": if self.flow.request: self.master.view_flow(self.flow) @@ -351,8 +352,8 @@ class FlowListBox(urwid.ListBox): if key == "A": for f in self.master.view: if f.intercepted: - f.resume(self.master) - signals.flowlist_change.send(self) + f.resume() + self.master.view.update(f) elif key == "z": self.master.view.clear() elif key == "e": diff --git a/mitmproxy/tools/console/flowview.py b/mitmproxy/tools/console/flowview.py index efeab647..a97a9b31 100644 --- a/mitmproxy/tools/console/flowview.py +++ b/mitmproxy/tools/console/flowview.py @@ -510,16 +510,16 @@ class FlowView(tabs.Tabs): # Pass scroll events to the wrapped widget self._w.keypress(size, key) elif key == "a": - self.flow.resume(self.master) - signals.flow_change.send(self, flow = self.flow) + self.flow.resume() + self.master.view.update(self.flow) elif key == "A": for f in self.view: if f.intercepted: - f.resume(self.master) - signals.flow_change.send(self, flow=f) + f.resume() + self.master.view.update(self.flow) elif key == "d": if self.flow.killable: - self.flow.kill(self.master) + self.flow.kill() self.view.remove(self.flow) if not self.view.focus.flow: self.master.view_flowlist() diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index adbbe160..ce18c6f0 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -226,31 +226,35 @@ class ClearAll(RequestHandler): class ResumeFlows(RequestHandler): def post(self): for f in self.view: - f.resume(self.master) + f.resume() + self.view.update(f) class KillFlows(RequestHandler): def post(self): for f in self.view: if f.killable: - f.kill(self.master) + f.kill() + self.view.update(f) class ResumeFlow(RequestHandler): def post(self, flow_id): - self.flow.resume(self.master) + self.flow.resume() + self.view.update(self.flow) class KillFlow(RequestHandler): def post(self, flow_id): if self.flow.killable: - self.flow.kill(self.master) + self.flow.kill() + self.view.update(self.flow) class FlowHandler(RequestHandler): def delete(self, flow_id): if self.flow.killable: - self.flow.kill(self.master) + self.flow.kill() self.view.remove(self.flow) def put(self, flow_id): diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py index db4855ff..68a3db70 100644 --- a/mitmproxy/tools/web/master.py +++ b/mitmproxy/tools/web/master.py @@ -31,9 +31,9 @@ class WebMaster(master.Master): self.addons.add(*addons.default_addons()) self.addons.add( + intercept.Intercept(), self.view, self.events, - intercept.Intercept(), termlog.TermLog(), ) self.app = app.Application( diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index c297e8f9..2256a7aa 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -1,5 +1,4 @@ from mitmproxy.test import tflow -import mock import io from mitmproxy.test import tutils @@ -97,21 +96,20 @@ class TestHTTPFlow: assert f.get_state() == f2.get_state() def test_kill(self): - fm = mock.Mock() f = tflow.tflow() f.reply.handle() - f.intercept(fm) + f.intercept() assert f.killable - f.kill(fm) + f.kill() assert not f.killable assert f.reply.value == Kill def test_resume(self): f = tflow.tflow() f.reply.handle() - f.intercept(mock.Mock()) + f.intercept() assert f.reply.state == "taken" - f.resume(mock.Mock()) + f.resume() assert f.reply.state == "committed" def test_replace_unicode(self): diff --git a/test/mitmproxy/test_web_app.py b/test/mitmproxy/test_web_app.py index 1fb5ccf0..6cf6ce26 100644 --- a/test/mitmproxy/test_web_app.py +++ b/test/mitmproxy/test_web_app.py @@ -83,7 +83,7 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): def test_resume(self): for f in self.view: f.reply.handle() - f.intercept(self.master) + f.intercept() assert self.fetch( "/flows/42/resume", method="POST").code == 200 @@ -95,7 +95,7 @@ class TestApp(tornado.testing.AsyncHTTPTestCase): for f in self.view: f.backup() f.reply.handle() - f.intercept(self.master) + f.intercept() assert self.fetch("/flows/42/kill", method="POST").code == 200 assert sum(f.killable for f in self.view) == 1 |