diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-07-13 23:26:04 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-07-13 23:26:04 +1200 |
commit | 7f8fd3cdffedb537f95773110d8ef2be60666133 (patch) | |
tree | 10234846fcb292c4139ad3248ef319f140da56cd /mitmproxy/controller.py | |
parent | c9a0fe6a0e6d70fa2aea1b8dc337609a9439ade1 (diff) | |
download | mitmproxy-7f8fd3cdffedb537f95773110d8ef2be60666133.tar.gz mitmproxy-7f8fd3cdffedb537f95773110d8ef2be60666133.tar.bz2 mitmproxy-7f8fd3cdffedb537f95773110d8ef2be60666133.zip |
Basic outline of addons
Add addons.py, integrate with our event mechanism, and change the Master API so
options is the first init argument.
Diffstat (limited to 'mitmproxy/controller.py')
-rw-r--r-- | mitmproxy/controller.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index e2be3a53..d09038f8 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -6,6 +6,8 @@ import contextlib from six.moves import queue +from mitmproxy import addons +from mitmproxy import options from . import ctx as mitmproxy_ctx from netlib import basethread from . import exceptions @@ -49,7 +51,9 @@ class Master(object): """ The master handles mitmproxy's main event loop. """ - def __init__(self, *servers): + def __init__(self, opts, *servers): + self.options = opts or options.Options() + self.addons = addons.Addons(self) self.event_queue = queue.Queue() self.should_exit = threading.Event() self.servers = [] @@ -121,6 +125,7 @@ class Master(object): for server in self.servers: server.shutdown() self.should_exit.set() + self.addons.done() class ServerThread(basethread.BaseThread): @@ -191,6 +196,10 @@ def handler(f): with master.handlecontext(): ret = f(master, message) + if handling: + # Python2/3 compatibility hack + fn = getattr(f, "func_name", None) or getattr(f, "__name__") + master.addons(fn) if handling and not message.reply.acked and not message.reply.taken: message.reply.ack() |