aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/addonmanager.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2017-03-16 15:40:43 +1300
committerAldo Cortesi <aldo@nullcube.com>2017-03-16 18:33:24 +1300
commitc5e0dc64b9b367eae8f4af66a4917c738dd87569 (patch)
tree8577458ea0e643e0f48d48e39dcb4f80a4317094 /mitmproxy/addonmanager.py
parent3de982900381b9d3743e65defbfa413453cd3836 (diff)
downloadmitmproxy-c5e0dc64b9b367eae8f4af66a4917c738dd87569.tar.gz
mitmproxy-c5e0dc64b9b367eae8f4af66a4917c738dd87569.tar.bz2
mitmproxy-c5e0dc64b9b367eae8f4af66a4917c738dd87569.zip
Rip out master handler mechanism
All events are now handled by addons, and we no longer support any events on master.
Diffstat (limited to 'mitmproxy/addonmanager.py')
-rw-r--r--mitmproxy/addonmanager.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py
index 123f64b2..670c4f24 100644
--- a/mitmproxy/addonmanager.py
+++ b/mitmproxy/addonmanager.py
@@ -1,5 +1,6 @@
from mitmproxy import exceptions
from mitmproxy import eventsequence
+from mitmproxy import controller
from . import ctx
import pprint
@@ -60,6 +61,32 @@ class AddonManager:
def __str__(self):
return pprint.pformat([str(i) for i in self.chain])
+ def handle_lifecycle(self, name, message):
+ """
+ Handle a lifecycle event.
+ """
+ if not hasattr(message, "reply"): # pragma: no cover
+ raise exceptions.ControlException(
+ "Message %s has no reply attribute" % message
+ )
+
+ # We can use DummyReply objects multiple times. We only clear them up on
+ # the next handler so that we can access value and state in the
+ # meantime.
+ if isinstance(message.reply, controller.DummyReply):
+ message.reply.reset()
+
+ self.trigger(name, message)
+
+ if message.reply.state != "taken":
+ message.reply.take()
+ if not message.reply.has_message:
+ message.reply.ack()
+ message.reply.commit()
+
+ if isinstance(message.reply, controller.DummyReply):
+ message.reply.mark_reset()
+
def invoke_addon(self, addon, name, *args, **kwargs):
"""
Invoke an event on an addon. This method must run within an